From f5b3f392d11d28e88191e415a9e0ae055656a808 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 31 Jul 2019 19:02:14 +0200 Subject: [PATCH] Update / fix JS and template following evolution of the API --- src/js/yunohost/controllers/diagnosis.js | 86 ++++++++++++------------ src/views/diagnosis/diagnosis_show.ms | 35 +++++----- 2 files changed, 61 insertions(+), 60 deletions(-) diff --git a/src/js/yunohost/controllers/diagnosis.js b/src/js/yunohost/controllers/diagnosis.js index 51492f46..6c583daf 100644 --- a/src/js/yunohost/controllers/diagnosis.js +++ b/src/js/yunohost/controllers/diagnosis.js @@ -11,50 +11,50 @@ app.get('#/diagnosis', function (c) { // Why this method ? - c.api('/diagnosis/show', function(data) { - for (var i = 0 ; i < data.reports.length ; i++) - { - // Convert timestamp to datetime - data.reports[i].time = new Date(data.reports[i].timestamp*1000); - for (var j = 0 ; j < data.reports[i].reports.length ; j++) - { - var type_ = data.reports[i].reports[j].report[0]; - type_ = type_.toLowerCase(); - var icon = ""; - var issue = false; + c.api('/diagnosis/show?full', function(data) { + for (var i = 0 ; i < data.reports.length ; i++) + { + // Convert timestamp to datetime + data.reports[i].time = new Date(data.reports[i].timestamp*1000); + for (var j = 0 ; j < data.reports[i].items.length ; j++) + { + var type_ = data.reports[i].items[j].status; + type_ = type_.toLowerCase(); + var icon = ""; + var issue = false; - if (type_ == "success") { - icon = "check-circle"; - } - else if (type_ == "warning") { - icon = "warning"; - issue = true; - } - else if (type_ == "error") { - type_ = "danger"; - icon = "times"; - issue = true; - } - data.reports[i].reports[j].report[0] = type_; - data.reports[i].reports[j].icon = icon; - data.reports[i].reports[j].issue = issue; - }; - }; - c.view('diagnosis/diagnosis_show', data, function() { - $(".rerun-diagnosis").click(function() { - var category = $(this).attr("category"); - c.api('/diagnosis/run?force', function(data) { - // This is a copy-pasta of some of the - // redirect/refresh code of sammy.js - // because for some reason calling the function did not work >.> - var to = "#/diagnosis"; - c.trigger('redirect', {to: to}); - c.app.last_location = c.path; - c.app.setLocation(to); - c.app.trigger('location-changed'); - }, 'POST', {"categories": [category]}); - }); - }); + if (type_ == "success") { + icon = "check-circle"; + } + else if (type_ == "warning") { + icon = "warning"; + issue = true; + } + else if (type_ == "error") { + type_ = "danger"; + icon = "times"; + issue = true; + } + data.reports[i].items[j].status = type_; + data.reports[i].items[j].icon = icon; + data.reports[i].items[j].issue = issue; + }; + }; + c.view('diagnosis/diagnosis_show', data, function() { + $(".rerun-diagnosis").click(function() { + var category = $(this).attr("category"); + c.api('/diagnosis/run?force', function(data) { + // This is a copy-pasta of some of the + // redirect/refresh code of sammy.js + // because for some reason calling the function did not work >.> + var to = "#/diagnosis"; + c.trigger('redirect', {to: to}); + c.app.last_location = c.path; + c.app.setLocation(to); + c.app.trigger('location-changed'); + }, 'POST', {"categories": [category]}); + }); + }); }, 'GET'); }); diff --git a/src/views/diagnosis/diagnosis_show.ms b/src/views/diagnosis/diagnosis_show.ms index d4df400f..7a99bb02 100644 --- a/src/views/diagnosis/diagnosis_show.ms +++ b/src/views/diagnosis/diagnosis_show.ms @@ -9,25 +9,26 @@
-
    -

    Last time ran : {{formatRelative time}}

    - {{#reports}} -
  • - {{#if icon}} - - {{/if}} - {{report.[1]}} - {{#if issue}} - {{t 'ignore'}} - {{t 'details'}} - {{/if}} - -
  • - {{/reports}} -
+
    +

    Last time ran : {{formatRelative time}}

    + {{#items}} +
  • + {{#if icon}} + + {{/if}} + {{summary}} + {{#if issue}} + {{t 'ignore'}} + {{/if}} + {{#if details}} + {{t 'details'}} + {{/if}} +
  • + {{/items}} +
{{/reports}}