index.php 20.9 KB
Newer Older
jlopez's avatar
jlopez committed
1
2
3
4
5
6
7
8
9
10
11
12
<?php
/**
 * Created by PhpStorm.
 * User: jimmy
 * Date: 11/12/18
 * Time: 14:30
 */

//$content = file_get_contents("container.json", FILE_USE_INCLUDE_PATH);

//$tools = json_decode($content)->containers;

jlopez's avatar
jlopez committed
13
14
session_start ();

jlopez's avatar
jlopez committed
15
require_once "./dao/DBquery.php";
remy's avatar
-a    
remy committed
16
require_once "./inc/php/printPanel.php";
jlopez's avatar
jlopez committed
17
18
19
20
21

$db = new DBquery();

$distribs = [];

jlopez's avatar
jlopez committed
22
$data_distribs = $db->getActiveDistributions();
jlopez's avatar
jlopez committed
23
24

foreach($data_distribs as $value){
jlopez's avatar
jlopez committed
25
    array_push($distribs,$value->name.":".$value->version);
jlopez's avatar
jlopez committed
26
27
}

jlopez's avatar
jlopez committed
28
$managers = $db->getManagers();
jlopez's avatar
jlopez committed
29

jlopez's avatar
jlopez committed
30
$data_section = $db->getActiveSection();
jlopez's avatar
jlopez committed
31
32

$section = array();
jlopez's avatar
jlopez committed
33
$section_visual = array();
jlopez's avatar
jlopez committed
34

jlopez's avatar
jlopez committed
35
36
37
38
$grade = $db->getGradeWithLogin($_SESSION['username']);

$labels = $db->getLabelsWithGrade($grade);

jlopez's avatar
jlopez committed
39
foreach ($db->getAllActiveSectionParent() as $s){
jlopez's avatar
jlopez committed
40
41
    if($s->active == 1) {
        array_push($section, $s->name);
jlopez's avatar
jlopez committed
42
        array_push($section_visual, $s->visual);
jlopez's avatar
jlopez committed
43
44
45
    }
}

jlopez's avatar
jlopez committed
46
require_once "./inc/php/buildHeader.php";
jlopez's avatar
jlopez committed
47

jlopez's avatar
jlopez committed
48
?>
jlopez's avatar
jlopez committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

    <div class="container-fluid">

        <br/>

        <div class="row">
            <div class="col-4">

                <div class="col-12">
                <div class="card border border-dark">
                    <div class="card-header bg-dark text-light">
                        Parameters :
                    </div>
                    <div class="card-body">
                        <div class="form-group">
remy's avatar
remy committed
64
                            <label for="imageNameInput" class="font-weight-bold">Image Name <span style="font-size:20px;" class="status text-danger">*</span>:</label>
jlopez's avatar
jlopez committed
65
66
67
68
                            <input type="text" class="form-control" id="imageNameInput">
                        </div>

                        <div class="form-group">
jlopez's avatar
jlopez committed
69
                            <label for="baseNameInput" class="font-weight-bold">From :</label>
jlopez's avatar
jlopez committed
70
                            <input type="text" class="form-control" id="baseNameInput">
jlopez's avatar
jlopez committed
71
                            <small id="help0" class="form-text text-muted">You can find images name on <a href="https://hub.docker.com/search?q=&type=image" >docker hub </a>.</small>
remy's avatar
remy committed
72
                            <small id="help1" class="form-text text-muted">If the above "From" field is empty, then <a href="https://docs.docker.com/engine/reference/builder/#from">"From"</a> is chosen from distribution bellow. </small>
jlopez's avatar
jlopez committed
73
74
75
76
                            <small id="help2" class="form-text text-muted">You must make sure that the OS of your base container is compatible with the chosen distribution. </small>
                        </div>

                        <div class="form-group">
remy's avatar
remy committed
77
                            <label for="selectedOS" class="font-weight-bold">Distribution <span style="font-size:20px;" class="status text-danger">*</span>:</label>
jlopez's avatar
jlopez committed
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
                            <select class="custom-select" id="selectedOS" onchange="hide_os_rows()">

                                <?php
                                    foreach ($distribs as $d){
                                        echo ' <option value="'.$d.'">'.$d.'</option>';
                                    }
                                ?>

                            </select>
                        </div>

                        <div class="form-group">
                            <label for="selectedOS" class="font-weight-bold">Package manager :</label>
                            <select class="custom-select" id="selectedInstaller">

                            <?php
jlopez's avatar
jlopez committed
94
95
                                    foreach ($managers as $manager){
                                        echo '<option value="'.$manager->value.'">'.$manager->value.'</option>';
jlopez's avatar
jlopez committed
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
                                    }
                            ?>

                            </select>
                        </div>

                        <div class="form-group">
                            <label for="containerType" class="font-weight-bold">Container type :</label>
                            <div class="custom-control custom-radio">
                                <input type="radio" id="singularityRadio" name="customRadio" class="custom-control-input" checked>
                                <label class="custom-control-label" for="singularityRadio">Singularity</label>
                            </div>
                            <div class="custom-control custom-radio">
                                <input type="radio" id="dockerRadio" name="customRadio" class="custom-control-input">
                                <label class="custom-control-label" for="dockerRadio">Docker</label>
                            </div>
                        </div>
                        <div class="form-group">
jlopez's avatar
jlopez committed
114
115
116
117
                            <button type="button" id="generateButton" class="btn btn-primary">Generate recipe</button>
                            <button type="button" id="downloadButton" class="btn btn-primary" onclick="downloadFile()">Download recipe</button>
                            <button type="button" id="generateButton" class="btn btn-primary" onclick="buildRecipe()">Build recipe</button>
                            <button type="button" id="generateButton" class="btn btn-primary">Push recipe</button>
jlopez's avatar
jlopez committed
118
                        </div>
jlopez's avatar
jlopez committed
119
120
121
122
123
124
125
126
127
128
129
130

                        <div class="form-group">

                        <?php 

                            if(isset($_SESSION['username']) && !empty($_SESSION['username']))
                            {
                                echo '<button type="button" class="btn btn-success" onclick="showFormContainer()">Publish recipe</button>';
                            }

                        ?>
                        </div>
jlopez's avatar
jlopez committed
131
132
133
134
135
136
137
138
139
140
141
142
143
144
                    </div>
                </div>

                </div>
                <br/>
                <div class="col-12">
                <div class="card border border-dark">
                    <div class="card-header bg-dark text-light">
                        Selected packages  :
                    </div>
                    <div class="card-body">
                        <table id="Table_SelectedPackages" class="table table-striped table-bordered">
                            <thead>
                            <tr>
jlopez's avatar
jlopez committed
145
                                <th></th>
jlopez's avatar
jlopez committed
146
                                <th>From</th>
jlopez's avatar
jlopez committed
147
148
                                <th>Name</th>
                     
jlopez's avatar
jlopez committed
149
150
151
152
153
154
155
156
157
                            </tr>
                            </thead>
                            <tbody id="TableSelectedPackages">

                            </tbody>
                        </table>
                    </div>
                </div>
                </div>
remy's avatar
remy committed
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175

                <br/>

                <div class="col-12">
                <div class="card border border-dark">
                    <div class="card-header bg-dark text-light">
                        Exec line (%Runscript / CMD) :
                    </div>
                    <div class="card-body">
                        <div class="form-group">
                            <label for="ExecLineInput" class="font-weight-bold">Exec Line :</label>
                            <input type="text" class="form-control" id="ExecLineInput" value='exec /bin/bash "$@"'>
                        </div>

                    </div>
                </div>
                </div>

jlopez's avatar
jlopez committed
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
            </div>

            <div class="col-8">
                <div class="card border border-dark">
                    <div class="card-header bg-dark text-light">
                        Tools :
                    </div>
                    <div class="card-body">
                        <nav>
                            <div class="nav nav-tabs" id="nav-tab" role="tablist">

                                <?php
                                $index = 0;
                                foreach ($section as $s) {
                                    if($index == 0) {
jlopez's avatar
jlopez committed
191
                                        echo '<a class="nav-item nav-link active" id="nav-'.$s.'-tab" data-toggle="tab" href="#nav-'.$s.'" role="tab" aria-controls="nav-'.$s.'" aria-selected="false">'.$section_visual[$index].'</a>';
jlopez's avatar
jlopez committed
192
                                    } else {
jlopez's avatar
jlopez committed
193
                                        echo '<a class="nav-item nav-link" id="nav-'.$s.'-tab" data-toggle="tab" href="#nav-'.$s.'" role="tab" aria-controls="nav-'.$s.'" aria-selected="false">'.$section_visual[$index].'</a>';
jlopez's avatar
jlopez committed
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
                                    }
                                    $index++;
                                }
                                ?>
                            </div>
                        </nav>
                        <div class="tab-content" id="nav-tabContent">
                            <?php
                            $index = 0;
                            foreach ($section as $s) {
                                if($index == 0) {
                                    echo '<div class="tab-pane fade show active" id="nav-'.$s.'" role="tabpanel" aria-labelledby="nav-'.$s.'-tab">';
                                }else {
                                    echo '<div class="tab-pane fade" id="nav-'.$s.'" role="tabpanel" aria-labelledby="nav-'.$s.'-tab">';
                                }

                                if($s == "R") {

                                    $subsection = array();

                                    foreach ($db->getSectionWhithParent("R") as $value){
                                        if($value[1]) {
                                            array_push($subsection, $value[0]);
                                        }
                                    }

                                    echo '
                                        <div class="form-group">
                                            <label for="selectedR" class="font-weight-bold">R version :</label>
                                            <select class="custom-select" id="selectedR">
                
jlopez's avatar
Fix #14    
jlopez committed
225
226
                                                <option value="0" >None</option>
                                                <option value="3.5" selected="selected">3.5</option>
jlopez's avatar
jlopez committed
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
                
                                            </select>
                                        </div>
                                        
                                        <nav>
                                            <div class="nav nav-tabs" id="nav-tab-R" role="tablist">
                                        
                                    ';


                                $indexSub = 0;
                                foreach ($subsection as $sub) {
                                    if($indexSub == 0) {
                                        echo '<a class="nav-item nav-link active" id="nav-'.$sub.'-tab-R" data-toggle="tab" href="#nav-'.$sub.'-R" role="tab" aria-controls="nav-'.$sub.'-R" aria-selected="false">'.$sub.'</a>';
                                    } else {
                                        echo '<a class="nav-item nav-link" id="nav-'.$sub.'-tab-R" data-toggle="tab" href="#nav-'.$sub.'-R" role="tab" aria-controls="nav-'.$sub.'-R" aria-selected="false">'.$sub.'</a>';
                                    }
                                    $indexSub++;
                                }


                                    echo '
                                            </div>
                                        </nav>
                                        <div class="tab-content" id="nav-tabContent-R">
                                    ';


                                    $indexSub = 0;
                                    foreach ($subsection as $sub) {
                                        if ($indexSub == 0) {
                                            echo '<div class="tab-pane fade show active" id="nav-' . $sub . '-R" role="tabpanel" aria-labelledby="nav-' . $s . '-tab-R">';
                                        } else {
                                            echo '<div class="tab-pane fade" id="nav-' . $sub . '-R" role="tabpanel" aria-labelledby="nav-' . $s . '-tab-R">';
                                        }

jlopez's avatar
jlopez committed
263
264
265
                                        
                                        printPanel($sub);
                                       
jlopez's avatar
jlopez committed
266
267
268
269
270
271
272

                                        echo '</div>';
                                        $indexSub++;
                                    }

                                    echo '</div>';
                                }
jlopez's avatar
jlopez committed
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
                                else if($s == "Python") {
                                    echo '

                                        <div class="form-group">
                                            <label for="selectedPython" class="font-weight-bold">Python version :</label>
                                            <select class="custom-select" id="selectedPython">
                
                                                <option value="0" selected="selected">None</option>
                                                <option value="3.7" >3.7</option>
                                                <option value="3.6" >3.6</option>
                                                <option value="3.5" >3.5</option>
                                                <option value="2.7" >2.7</option>
                                            </select>
                                        </div>
                                    ';
jlopez's avatar
jlopez committed
288

jlopez's avatar
jlopez committed
289
                                    printPanel($s);
jlopez's avatar
jlopez committed
290
291

                                }
jlopez's avatar
jlopez committed
292
293
                                else {
                                    printPanel($s);
jlopez's avatar
jlopez committed
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
                                }

                                echo '</div>';
                                $index++;
                            }
                            ?>
                        </div>
                    </div>
                </div>
            </div>

        </div>

        <br/>

jlopez's avatar
jlopez committed
309

jlopez's avatar
jlopez committed
310
311
312
313
314
315
316
317
318
319
320
321
            <div class="col-12">
                <div class="card border border-dark" id = "containerPreviewHead">
                    <div class="card-header bg-dark text-light">
                        Preview File :
                    </div>
                    <div class="card-body">
                        <div class="form-group">
                            <textarea id="containerPreview"  class="form-control" rows="3"></textarea>
                        </div>
                    </div>
                </div>
            </div>
jlopez's avatar
jlopez committed
322

jlopez's avatar
jlopez committed
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
        <!-- Start Modal Publish -->
        <div class="modal" id="modalSaveRecipe">
            <div class="modal-dialog">
            <div class="modal-content">
            
                <!-- Modal Header -->
                <div class="modal-header">
                <h4 class="modal-title">Publish container file</h4>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                </div>
                <form action="./action/action_container.php" method="post">
                    <!-- Modal body -->
                    <div class="modal-body">
                        
                        <input type="text" class="form-control" style="display: none;" placeholder="action" name="action" value="create">
                        <textarea type="text" rows="5" class="form-control" id="valueContainer" style="display: none;" name="value" value=""></textarea>
                            <div class="form-group">
                                <label for="nameContainer">Name :</label>
                                <input type="text" class="form-control" id="nameContainer" name="name" required>
                            </div>
                            <div class="form-group">
                                <label for="typeContainer">Type :</label>
                                <input type="text" class="form-control" id="typeContainer" name="type" value="" readonly>

                            </div>
                            <div class="form-group">
                                <label for="visibilityContainer">Visibility :</label>
                                <select class="form-control" id="visibilityContainer" name="visibility">
                                    <option value="1">Public</option>
                                    <option value="0">Private</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="descriptionContainer">Description :</label>
                                <textarea class="form-control" rows="5" id="descriptionContainer" maxlength="500" name ="description" required></textarea>
                            </div> 
jlopez's avatar
jlopez committed
359
360
361
362
363
364
365
366
367
                            <div class="form-group">
                                <label for="labelsContainer">Labels :</label>
                                <select class="form-control" id="labelsContainer" name="labels[]" multiple>
                                <?php
                                    foreach ($labels as $label){
                                        echo '<option value="'.$label->ID.'">'.$label->name.'</option>';
                                    }
                                ?>
                                </select>
jlopez's avatar
jlopez committed
368

jlopez's avatar
jlopez committed
369
                            </div>
jlopez's avatar
jlopez committed
370
371
372
373
                            <div class="form-group">
                                <label for="tagsContainer">Tags :</label>
                                <textarea class="form-control" rows="5" id="tagsContainer" maxlength="500" name ="tags"></textarea>
                            </div> 
jlopez's avatar
jlopez committed
374
375
376
                    
                    </div>

jlopez's avatar
jlopez committed
377

jlopez's avatar
jlopez committed
378
379
380
381
382
383
                    
                    <!-- Modal footer -->
                    <div class="modal-footer">
                    <button type="submit" class="btn btn-success">Submit</button>
                    <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
                    </div>
jlopez's avatar
jlopez committed
384

jlopez's avatar
jlopez committed
385
386
387
388
389
390
                </form>
                
            </div>
            </div>
        </div>  <!-- End Modal Publish -->
       
jlopez's avatar
jlopez committed
391
392
393
394
395
396
397
398
    </div>

    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"  crossorigin="anonymous"></script>
remy's avatar
remy committed
399
400

    <!-- local fallbacks -->
401
    <script src="./inc/js/jquery-3.2.1.slim.min.js"></script>
remy's avatar
remy committed
402
403
    <script src="./inc/js/popper.min.js"></script>
    <script src="./inc/js/bootstrap.min.js"></script>
404
    <script src="./inc/js/jquery.dataTables.min.js"></script>
remy's avatar
remy committed
405
406

    <script src="./inc/js/wicopa.js"></script>
jlopez's avatar
jlopez committed
407
408
    <script>

jlopez's avatar
jlopez committed
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
        $(function()
        {

            <?php
                foreach ($data_section as $s) {
                    echo 'SELECTED_PACKAGES["'.$s->name.'"] = [];';
                    echo '';
                }

                foreach ($data_section as $s) {
                    echo 'SELECTED_PACKAGES_COLOR["'.$s->name.'"] = "' . $s->color . '";' ;
                    echo '';
                }

            ?>

            hide_os_rows();


        });

jlopez's avatar
jlopez committed
430

jlopez's avatar
jlopez committed
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
        function hide_os_rows() {
            var e = document.getElementById("selectedOS");
            var selectedOSRelease = e.options[e.selectedIndex].value;

            var res = "tr.table_container_" + selectedOSRelease.replace(":", "_").replace(".", "_");

            for (var i = 0; i < e.length; i++) {

                res = "tr.table_container_" + e[i].value.replace(":", "_").replace(".", "_");
                if (e[i].value !== selectedOSRelease) {
                    $(res).hide();
                } else {
                    $(res).show();
                }

            }

            var options = document.getElementById('selectedInstaller').getElementsByTagName('option');

            <?php

                foreach($data_distribs as $value){

jlopez's avatar
jlopez committed
454
                    echo "if(selectedOSRelease.includes(\"$value->name\")) {\n";
jlopez's avatar
jlopez committed
455

jlopez's avatar
jlopez committed
456
457
458
459
460
                    echo "for(var i = 0; i < options.length; i++)  {\n";
                            echo "if(options[i].value == \"$value->manager\") {\n";
                                echo "document.getElementById('selectedInstaller').getElementsByTagName('option')[i].selected = 'selected'\n";
                            echo "}\n";
                    echo "}\n";
jlopez's avatar
jlopez committed
461

jlopez's avatar
jlopez committed
462
                    echo "}\n";
jlopez's avatar
jlopez committed
463
464
465
466
467
468
469
470
                }

            ?>

            document.getElementById("selectedInstaller").disabled = true;

            SELECTED_PACKAGES["Distribution"] = [];

jlopez's avatar
Fix #14    
jlopez committed
471
            //document.getElementById("containDistributionPackages").innerHTML = '';
jlopez's avatar
jlopez committed
472
473
474
475
476
477

            gestionPackageSelected();
        }

    </script>
  </body>
remy's avatar
remy committed
478
</html>