diff --git a/src/js/yunohost/controllers/services.js b/src/js/yunohost/controllers/services.js index 113c34fc..492fe18b 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,28 +40,26 @@ // 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') + c.api('GET', '/services/'+ c.params['service'] +'/log', {number: 50}, function(data_log) { + + 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() { + + 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'); @@ -77,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/js/yunohost/helpers.js b/src/js/yunohost/helpers.js index 0cbc3b3f..d7c3dfc1 100644 --- a/src/js/yunohost/helpers.js +++ b/src/js/yunohost/helpers.js @@ -336,9 +336,6 @@ } }); - // Paste
helper - c.prePaste(); - // Run callback callback(); @@ -493,39 +490,7 @@ str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); } return str.join("&"); - }, - - - // - // 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(); - }); - }); } - }); + }); })(); diff --git a/src/locales/en.json b/src/locales/en.json index de095ed8..35145778 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..4c0c0356 100644 --- a/src/views/service/service_info.ms +++ b/src/views/service/service_info.ms @@ -1,7 +1,7 @@@@ -9,76 +9,67 @@--{{t 'infos'}}
+{{t name}}
+ {{#if (eq status "running")}} + + {{else}} + + {{/if}}- {{#service}} --
- {{/service}} +- {{t 'name'}}
-- {{name}}
-- {{t 'description'}}
-- {{description}}
-+ +
- {{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 'logs'}}
+-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 @@- {{#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}} - - {{/is_running}} - {{^is_running}} - - {{/is_running}} - - {{t 'log'}} - -- - {{/service}} -+ {{#logs}} +{{filename}}
+{{filecontent}}+ {{/logs}}{{name}} {{description}}
- {{t 'service_status'}} - - {{active}} - -{{/services}} 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 @@ - - - - -
- {{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" }}- {{#logs}} -{{filename}}
-{{filecontent}}- - {{/logs}} -