guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Mathieu Othacehe
Date: Tue, 23 Mar 2021 06:06:39 -0400 (EDT)

branch: master
commit 9fbf6991fa95226be0da88da706828d232d91164
Author: Mathieu Othacehe <othacehe@gnu.org>
AuthorDate: Sun Mar 21 12:21:58 2021 +0100

    Add build parameter edition field.
---
 Makefile.am                    |   2 +
 src/cuirass/http.scm           |  16 +++++-
 src/cuirass/templates.scm      | 111 +++++++++++++++++++++++++++++++++++------
 src/static/css/choices.min.css |   1 +
 src/static/js/choices.min.js   |  11 ++++
 5 files changed, 123 insertions(+), 18 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index f970046..4806036 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -87,6 +87,7 @@ dist_sql_DATA =                               \
   src/sql/upgrade-1.sql
 
 dist_css_DATA =                                        \
+  src/static/css/choices.min.css               \
   src/static/css/cuirass.css                   \
   src/static/css/bootstrap.css                 \
   src/static/css/open-iconic-bootstrap.css
@@ -101,6 +102,7 @@ dist_images_DATA =                          \
   src/static/images/icon.png
 dist_js_DATA =                                 \
   src/static/js/chart.js                        \
+  src/static/js/choices.min.js                  \
   src/static/js/jquery-3.6.0.min.js
 
 TEST_EXTENSIONS = .scm .sh
diff --git a/src/cuirass/http.scm b/src/cuirass/http.scm
index 613b8be..6979131 100644
--- a/src/cuirass/http.scm
+++ b/src/cuirass/http.scm
@@ -77,6 +77,7 @@
 
 (define %file-white-list
   '("css/bootstrap.css"
+    "css/choices.min.css"
     "css/cuirass.css"
     "css/open-iconic-bootstrap.css"
     "fonts/open-iconic.otf"
@@ -84,7 +85,8 @@
     "images/icon.png"
     "images/guix.png"
     "js/chart.js"
-    "js/jquery-3.6.0.min.js"))
+    "js/jquery-3.6.0.min.js"
+    "js/choices.min.js"))
 
 (define (build->hydra-build build)
   "Convert BUILD to an assoc list matching hydra API format."
@@ -364,6 +366,14 @@ into a specification record and return it."
          (name (assq-ref params 'name))
          (build (string->symbol
                  (assq-ref params 'build)))
+         (build-params (or (and (assq-ref params 'param-select)
+                                (map string->symbol
+                                     (filter-field 'param-select)))
+                           (let ((param (assq-ref params 'param-input)))
+                             (and param
+                                  (not (string=? param ""))
+                                  (string-split
+                                   (uri-decode param) #\,)))))
          (channels (map (lambda (name url branch)
                           (channel
                            (name (string->symbol name))
@@ -383,7 +393,9 @@ into a specification record and return it."
                    %cuirass-supported-systems)))
     (specification
      (name name)
-     (build build)
+     (build (if build-params
+                (cons build build-params)
+                build))
      (channels channels)
      (priority priority)
      (systems systems))))
diff --git a/src/cuirass/templates.scm b/src/cuirass/templates.scm
index 9fd4f08..8fccbb5 100644
--- a/src/cuirass/templates.scm
+++ b/src/cuirass/templates.scm
@@ -120,6 +120,8 @@ system whose names start with " (code "guile-") ":" (br)
           (link (@ (rel "stylesheet")
                    (href "/static/css/open-iconic-bootstrap.css")))
           (link (@ (rel "stylesheet")
+                   (href "/static/css/choices.min.css")))
+          (link (@ (rel "stylesheet")
                    (href "/static/css/cuirass.css")))
           (link (@ (rel "icon") (type "image/png")
                    (href "/static/images/icon.png")))
@@ -239,8 +241,11 @@ system whose names start with " (code "guile-") ":" (br)
                    `(tr (td (a (@ (href "/jobset/"
                                         ,(specification-name spec)))
                                ,(specification-name spec)))
-                        (td ,(symbol->string
-                              (specification-build spec)))
+                        (td ,(match (specification-build spec)
+                               ((? symbol? build)
+                                (symbol->string build))
+                               ((build _ ...)
+                                (symbol->string build))))
                         (td ,(string-join
                               (map (lambda (channel)
                                      (format #f "~a (on ~a)"
@@ -295,8 +300,7 @@ the existing SPEC otherwise."
                        (div (@ (class "col-sm-2"))
                             (input
                              (@ (type "text")
-                                (class "form-control")
-                                (id "channel-name")
+                                (class "form-control channel-name")
                                 (name "channel-name")
                                 (placeholder "name")
                                 (value ,name)
@@ -304,8 +308,7 @@ the existing SPEC otherwise."
                        (div (@ (class "col-sm-4"))
                             (input
                              (@ (type "text")
-                                (class "form-control")
-                                (id "channel-url")
+                                (class "form-control channel-url")
                                 (name "channel-url")
                                 (placeholder "url")
                                 (value ,url)
@@ -313,21 +316,20 @@ the existing SPEC otherwise."
                        (div (@ (class "col-sm-2"))
                             (input
                              (@ (type "text")
-                                (class "form-control")
-                                (id "channel-branch")
+                                (class "form-control channel-branch")
                                 (name "channel-branch")
                                 (placeholder "branch")
                                 (value ,branch)
                                 (required))))
                        ,@(if first-row?
                              '((a (@ (class "btn btn-success add-channel")
-                                      (href "#")
-                                      (role "button"))
-                                   "Add"))
+                                     (href "#")
+                                     (role "button"))
+                                  "Add"))
                              '((a (@ (class "btn btn-danger remove-channel")
-                                      (href "#")
-                                      (role "button"))
-                                   "Remove"))))
+                                     (href "#")
+                                     (role "button"))
+                                  "Remove"))))
                  html)))
             '()
             channels)))
@@ -336,7 +338,9 @@ the existing SPEC otherwise."
          (list first `(div (@ (class "channels")) ,@rest))))))
 
   (let ((name (and spec (specification-name spec)))
-        (build (and spec (specification-build spec)))
+        (build (and spec (match (specification-build spec)
+                           ((? symbol? build) build)
+                           ((build _ ...) build))))
         (channels (and spec (specification-channels spec)))
         (priority (and spec (specification-priority spec)))
         (systems (and spec (specification-systems spec))))
@@ -346,6 +350,7 @@ the existing SPEC otherwise."
               (format #f "Edit ~a specification" name)
               "Create a new specification"))
       (script (@ (src "/static/js/jquery-3.6.0.min.js")))
+      (script (@ (src "/static/js/choices.min.js")))
       (script "
 $(document).ready(function() {
 var counter = 0;
@@ -392,6 +397,51 @@ if (checked_cbs == 0) {
       }, false)
     })
 })();
+
+const select_choices = new Choices($('.build-param-select')[0], {
+  removeItemButton: true,
+  duplicateItemsAllowed: false,
+});
+const input_choices = new Choices($('.build-param-input')[0], {
+  removeItemButton: true,
+  duplicateItemsAllowed: false,
+});
+$('.build-param-select').on('showDropdown', function() {
+  var names = $('.channel-name').map(function() {
+    var name = $(this).val();
+    return { 'value': name, 'label': name};
+  }).toArray();
+  select_choices.setChoices(names, 'value', 'label', true);
+});
+var param_select = $('.build-select');
+var param_select_cb = function(){
+  var val = param_select.val();
+  if (['packages', 'manifests'].indexOf(val) >= 0) {
+    input_choices.clearStore();
+    $('.param-input-row').show();
+  } else {
+    $('.param-input-row').hide();
+  }
+
+  if (['channels'].indexOf(val) >= 0) {
+    $('.param-select-row').show();
+  } else {
+    $('.param-select-row').hide();
+  }
+};
+param_select_cb();
+param_select.change(param_select_cb);
+
+const default_param = $('.default-build-param');
+if (default_param.length) {
+var items = default_param.text().split(',').map(function(name) {
+  return { 'value': name, 'label': name, selected: true};
+});
+if ($('.param-select-row').is(':visible')) {
+  select_choices.setChoices(items, 'value', 'label', true);
+} else if ($('.param-input-row').is(':visible')) {
+  input_choices.setValue(items);
+}}
 });")
       (form (@ (id "add-specification")
                (class "needs-validation")
@@ -419,7 +469,7 @@ if (checked_cbs == 0) {
                         "Build")
                  (div (@ (class "col-sm-4"))
                       (select
-                       (@ (class "form-control")
+                       (@ (class "form-control build-select")
                           (id "build")
                           (name "build"))
                        ,@(map (lambda (type)
@@ -428,6 +478,35 @@ if (checked_cbs == 0) {
                                                   '()))
                                          ,(symbol->string type)))
                               %build-types))))
+            ,(if spec
+                 (match (specification-build spec)
+                   ((build . rest)
+                    `((span (@ (class "default-build-param")
+                               (hidden "true"))
+                            ,(string-join
+                              (map (lambda (param)
+                                     (if (symbol? param)
+                                         (symbol->string param)
+                                         param))
+                                   rest)
+                              ","))))
+                   (else ""))
+                 '())
+            (div (@ (class "form-group row param-select-row"))
+                 (label (@(class "col-sm-2 col-form-label"))
+                        "Parameter")
+                 (div (@ (class "col-sm-4"))
+                      (select (@ (type "text")
+                                 (class "form-control build-param-select")
+                                 (name "param-select")
+                                 (multiple)))))
+            (div (@ (class "form-group row param-input-row"))
+                 (label (@(class "col-sm-2 col-form-label"))
+                        "Parameter")
+                 (div (@ (class "col-sm-4"))
+                      (input (@ (type "text")
+                                (name "param-input")
+                                (class "form-control build-param-input")))))
             ,@(channels->html
                (if spec channels (list %default-guix-channel)))
             (div (@ (class "form-group row"))
diff --git a/src/static/css/choices.min.css b/src/static/css/choices.min.css
new file mode 100644
index 0000000..19adaba
--- /dev/null
+++ b/src/static/css/choices.min.css
@@ -0,0 +1 @@
+.choices{position:relative;margin-bottom:24px;font-size:16px}.choices:focus{outline:0}.choices:last-child{margin-bottom:0}.choices.is-disabled
 .choices__inner,.choices.is-disabled 
.choices__input{background-color:#eaeaea;cursor:not-allowed;-webkit-user-select:none;-ms-user-select:none;user-select:none}.choices.is-disabled
 .choices__item{cursor:not-allowed}.choices 
[hidden]{display:none!important}.choices[data-type*=select-one]{cursor:pointer}.choices[data-type*=select-one]
 .choices__inne [...]
\ No newline at end of file
diff --git a/src/static/js/choices.min.js b/src/static/js/choices.min.js
new file mode 100644
index 0000000..c3eabfa
--- /dev/null
+++ b/src/static/js/choices.min.js
@@ -0,0 +1,11 @@
+/*! choices.js v9.0.1 | © 2019 Josh Johnson | 
https://github.com/jshjohnson/Choices#readme */
+window.Choices=function(e){var t={};function i(n){if(t[n])return 
t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return 
e[n].call(s.exports,s,s.exports,i),s.l=!0,s.exports}return 
i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof
 
Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return
 e; [...]
+/*!
+ * Fuse.js v3.4.5 - Lightweight fuzzy-search (http://fusejs.io)
+ * 
+ * Copyright (c) 2012-2017 Kirollos Risk (http://kiro.me)
+ * All Rights Reserved. Apache Software License 2.0
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ */
+e.exports=function(e){var t={};function i(n){if(t[n])return t[n].exports;var 
s=t[n]={i:n,l:!1,exports:{}};return 
e[n].call(s.exports,s,s.exports,i),s.l=!0,s.exports}return 
i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof
 
Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return
 e;if(4& [...]
\ No newline at end of file



reply via email to

[Prev in Thread] Current Thread [Next in Thread]