From fb8b3071f997788fcdff2fb1a4efd8fc07591949 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 7 Nov 2019 22:56:20 +0100 Subject: [PATCH 1/3] Clean / update service view, followup of PR in the core --- src/js/yunohost/controllers/services.js | 31 ++------- src/locales/en.json | 5 +- src/views/service/service_info.ms | 93 ++++++++++++------------- src/views/service/service_list.ms | 22 +++--- 4 files changed, 64 insertions(+), 87 deletions(-) diff --git a/src/js/yunohost/controllers/services.js b/src/js/yunohost/controllers/services.js index 113c34fc..0445843a 100644 --- a/src/js/yunohost/controllers/services.js +++ b/src/js/yunohost/controllers/services.js @@ -16,15 +16,9 @@ }; $.each(data, function(k, v) { v.name = k; - // Handlebars want booleans - v.is_loaded = (v.loaded=='enabled') ? true : false; - v.is_running = (v.active=='active') ? true : false; - // Translate status and loaded state - v.status = y18n.t(v.status); - v.loaded = y18n.t(v.loaded); - if (v.active_at == 'unknown') + if (v.last_state_change == 'unknown') { - delete v.active_at; + v.last_state_change = 0; } data2.services.push(v); }); @@ -46,25 +40,12 @@ // Status & actions for a service app.get('#/services/:service', function (c) { c.api('GET', '/services/'+ c.params['service'], {}, function(data) { - var data2 = { - service: data - }; - data2.service.name = c.params['service']; - // Handlebars want booleans - data2.service.is_loaded = (data.loaded=='enabled') ? true : false; - data2.service.is_running = (data.active=='active') ? true : false; - // Translate status and loaded state - data2.service.active = y18n.t(data.active); - data2.service.loaded = y18n.t(data.loaded); - if (data.active_at != 'unknown') + data.name = c.params['service']; + if (data.last_state_change == 'unknown') { - data2.service.active_at = data.active_at; + data.last_state_change = 0; } - else - { - data2.service.active_at = 0; - } - c.view('service/service_info', data2, function() { + c.view('service/service_info', data, function() { // Configure behavior for enable/disable and start/stop buttons $('button[data-action]').on('click', function() { diff --git a/src/locales/en.json b/src/locales/en.json index 3be53381..d353a336 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -53,6 +53,7 @@ "cancel": "Cancel", "check": "Check", "close": "Close", + "configuration": "Configuration", "confirm_app_change_url": "Are you sure you want to change the app access URL?", "confirm_app_default": "Are you sure you want to make this app default?", "confirm_change_maindomain": "Are you sure you want to change the main domain?", @@ -269,15 +270,15 @@ "select_none": "Select none", "service_description": "Description:", "service_log": "%s log", - "service_start_on_boot": "Start on boot: ", + "service_start_on_boot": "Start on boot", "service_status": "Status: ", "services": "Services", "services_list": "Service list", "set_default": "Set default", "size": "Size", + "since": "since", "skip": "Skip", "start": "Start", - "started_at": "Started at:", "status": "Status", "stop": "Stop", "storage_create": "Add remote storage", diff --git a/src/views/service/service_info.ms b/src/views/service/service_info.ms index 2e78941d..ad6809de 100644 --- a/src/views/service/service_info.ms +++ b/src/views/service/service_info.ms @@ -1,7 +1,7 @@
{{t 'home'}} {{t 'services'}} - {{service.name}} + {{name}}
@@ -12,73 +12,70 @@

{{t 'infos'}}

- {{#service}} -
-
{{t 'name'}}
-
{{name}}
-
{{t 'description'}}
-
{{description}}
-
- {{/service}} +
+ +
{{t 'name'}}
+
{{name}}
+ +
{{t 'description'}}
+
{{description}}
+ +
{{t 'status'}}
+
+ {{#if (eq status "running")}} + + + {{else}} + + + {{/if}} + {{t status}} {{t 'since'}} {{formatRelative last_state_change day="numeric" month="long" year="numeric" hour="numeric" minute="numeric" }} +
+ +
{{t 'service_start_on_boot'}}
+ {{#if (eq start_on_boot "enabled")}} +
+ {{else}} +
+ {{/if}} + {{t start_on_boot}} +
+ +
{{t 'configuration'}}
+ {{#if (eq configuration "valid")}} +
+ {{else if (eq configuration "broken")}} +
+ {{else}} +
+ {{/if}} + {{t configuration}} +
+
-

{{t 'status'}}

+

{{t 'operations'}}

- {{#service}} -
- {{t 'service_start_on_boot'}} - - {{loaded}} - -
- {{t 'service_status'}} - - {{active}} - -
- {{t 'started_at'}} - {{#active_at}} - {{formatTime . day="numeric" month="long" year="numeric" hour="numeric" minute="numeric"}} - {{/active_at}} - {{^active_at}} - {{t 'unknown'}} - {{/active_at}} -
-
- {{#is_loaded}} - - {{/is_loaded}} - {{^is_loaded}} - - {{/is_loaded}} - - {{#is_running}} + {{#if (eq status "running")}} - {{/is_running}} - {{^is_running}} + {{else}} - {{/is_running}} + {{/if}} {{t 'log'}} -
- {{/service}}
diff --git a/src/views/service/service_list.ms b/src/views/service/service_list.ms index dbffb18e..29359608 100644 --- a/src/views/service/service_list.ms +++ b/src/views/service/service_list.ms @@ -11,18 +11,16 @@

{{name}} {{description}}

- {{t 'service_status'}} - - {{active}} - -
- {{t 'started_at'}} - {{#active_at}} - {{formatTime . day="numeric" month="long" year="numeric" hour="numeric" minute="numeric"}} - {{/active_at}} - {{^active_at}} - {{t 'unknown'}} - {{/active_at}} + {{#if (eq status "running")}} + + + {{else}} + + + {{/if}} + {{t status}} + + {{t 'since'}} {{formatRelative last_state_change day="numeric" month="long" year="numeric" hour="numeric" minute="numeric" }}
{{/services}} From e187e4b61a449ea7a06ccd4c0673d2420ffa7164 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 7 Nov 2019 23:00:09 +0100 Subject: [PATCH 2/3] Drop the service 'log' button ... those logs are not helpful, to be improved / recplaced by ljf's work --- src/js/yunohost/helpers.js | 46 ------------------------------- src/views/service/service_info.ms | 3 -- src/views/service/service_log.ms | 16 ----------- 3 files changed, 65 deletions(-) delete mode 100644 src/views/service/service_log.ms diff --git a/src/js/yunohost/helpers.js b/src/js/yunohost/helpers.js index 59e70ed0..b7b01321 100644 --- a/src/js/yunohost/helpers.js +++ b/src/js/yunohost/helpers.js @@ -336,9 +336,6 @@ } }); - // Paste
 helper
-                    c.prePaste();
-
                     // Run callback
                     callback();
 
@@ -496,49 +493,6 @@
         },
 
 
-        //
-        // Misc helpers used in views etc..
-        //
-
-        // Paste 
-        prePaste: function() {
-            var pasteButtons = $('button[data-paste-content],a[data-paste-content]');
-            pasteButtons.on('click', function(){
-                // Get paste content element
-                var preElement = $($(this).data('paste-content'));
-
-                c.showLoader();
-
-                // Send to paste.yunohost.org
-                $.ajax({
-                    type: "POST",
-                    url: 'https://paste.yunohost.org/documents',
-                    data: preElement.text(),
-                })
-                .success(function(data, textStatus, jqXHR) {
-                    window.open('https://paste.yunohost.org/' + data.key, '_blank');
-                })
-                .fail(function() {
-                    c.flash('fail', y18n.t('paste_error'));
-                })
-                .always(function(){
-                    c.hideLoader();
-                });
-            });
-        },
-
-        force_redirect: function(to) {
-            c = this;
-            // This is a copy-pasta of some of the redirect/refresh code of
-            // sammy.js because for some reason calling the origina
-            // redirect/refresh function in some context does not work >.>
-            // (e.g. if you're already on the page)
-            c.trigger('redirect', {to: to});
-            c.app.last_location = c.path;
-            c.app.setLocation(to);
-            c.app.trigger('location-changed');
-        }
-
     });
 
 })();
diff --git a/src/views/service/service_info.ms b/src/views/service/service_info.ms
index ad6809de..711e2902 100644
--- a/src/views/service/service_info.ms
+++ b/src/views/service/service_info.ms
@@ -72,9 +72,6 @@
                  {{t 'start'}}
             
         {{/if}}
-            
-                 {{t 'log'}}
-            
 
         
     
diff --git a/src/views/service/service_log.ms b/src/views/service/service_log.ms
deleted file mode 100644
index 937b6c1d..00000000
--- a/src/views/service/service_log.ms
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
- -
- {{#logs}} -

{{filename}}

-
{{filecontent}}
- - {{/logs}} -
From c6b1bfb1c2b051299dcf20a6d6a030a694baa12b Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 18 Nov 2019 16:10:58 +0100 Subject: [PATCH 3/3] Reingrate log view directly at the bottom of the service status page, now that we have at least the journalctl as a meaninful log. + various cosmetic and button tweaks --- src/js/yunohost/controllers/services.js | 58 +++++++++++++++---------- src/views/service/service_info.ms | 37 ++++++++-------- 2 files changed, 53 insertions(+), 42 deletions(-) diff --git a/src/js/yunohost/controllers/services.js b/src/js/yunohost/controllers/services.js index 0445843a..492fe18b 100644 --- a/src/js/yunohost/controllers/services.js +++ b/src/js/yunohost/controllers/services.js @@ -40,15 +40,26 @@ // Status & actions for a service app.get('#/services/:service', function (c) { c.api('GET', '/services/'+ c.params['service'], {}, function(data) { + c.api('GET', '/services/'+ c.params['service'] +'/log', {number: 50}, function(data_log) { + data.name = c.params['service']; if (data.last_state_change == 'unknown') { data.last_state_change = 0; } + + data.logs = []; + $.each(data_log, function(k, v) { + data.logs.push({filename: k, filecontent: v.join('\n')}); + }); + + // Sort logs by filename, put the journalctl/systemd log on top + data.logs.sort(function(a,b) { return a.filename === "journalctl" ? -1 : b.filename === "journalctl" ? 1 : a.filename < b.filename ? -1 : a.filename > b.filename ? 1 : 0; }); + c.view('service/service_info', data, function() { // Configure behavior for enable/disable and start/stop buttons - $('button[data-action]').on('click', function() { + $('button[data-action="start"], button[data-action="stop"]').on('click', function() { var service = $(this).data('service'); var action = $(this).data('action'); @@ -58,32 +69,35 @@ var method = null, endurl = service; - switch (action) { - case 'start': - method = 'PUT'; - break; - case 'stop': - method = 'DELETE'; - break; - case 'enable': - method = 'PUT'; - endurl += '/enable'; - break; - case 'disable': - method = 'DELETE'; - endurl += '/enable'; - break; - default: - c.flash('fail', y18n.t('unknown_action', [action])); - c.refresh(); - return; - } - + method = action === "start" ? 'PUT' : 'DELETE'; c.api(method, '/services/'+ endurl, {}, function() { c.refresh(); }); }); }); + + // Configure behavior for enable/disable and start/stop buttons + $('button[data-action="share"]').on('click', function() { + + c.showLoader(); + + // Send to paste.yunohost.org + $.ajax({ + type: "POST", + url: 'https://paste.yunohost.org/documents', + data: $("#logs").text(), + }) + .success(function(data, textStatus, jqXHR) { + window.open('https://paste.yunohost.org/' + data.key, '_blank'); + }) + .fail(function() { + c.flash('fail', y18n.t('paste_error')); + }) + .always(function(){ + c.hideLoader(); + }); + }); }); }); + }); }); // Service log diff --git a/src/views/service/service_info.ms b/src/views/service/service_info.ms index 711e2902..4c0c0356 100644 --- a/src/views/service/service_info.ms +++ b/src/views/service/service_info.ms @@ -9,14 +9,20 @@
-

{{t 'infos'}}

+

{{t name}}

+ {{#if (eq status "running")}} + + {{else}} + + {{/if}}
-
{{t 'name'}}
-
{{name}}
-
{{t 'description'}}
{{description}}
@@ -55,24 +61,15 @@
-
-

{{t 'operations'}}

+

{{t 'logs'}}

+
-
-
- - {{#if (eq status "running")}} - - {{else}} - - {{/if}} - -
+
+ {{#logs}} +

{{filename}}

+
{{filecontent}}
+ {{/logs}}