summaryrefslogtreecommitdiff
path: root/mobmonitor/static/js/main.js
blob: f09d36c42e15a5d00ec977fe39ea30f9f3d5e11a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2015 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

'use strict';


var HEALTH_DISPLAY_REFRESH_MS = 1000;


$(document).ready(function() {
  // Setup the health status widget.
  $('#healthStatusDisplay').healthDisplay();
  $('#healthStatusDisplay').healthDisplay('refreshHealthDisplay');

  setInterval(function() {
    $('#healthStatusDisplay').healthDisplay('refreshHealthDisplay');
  }, HEALTH_DISPLAY_REFRESH_MS);

  // Setup the log collection button.
  $(document).on('click', '.collect-logs', function() {
    window.open('/CollectLogs', '_blank');
  });

  // Setup the repair action buttons
  $(document).on('click', '.run-repair-action', function() {
    // Retrieve the service and action for this repair button.
    var action = $(this).attr('action');
    var healthcheck = $(this).closest('.healthcheck-info').attr('hcname');
    var service = $(this).closest('.health-container').attr('id');
    if (service.indexOf(SERVICE_CONTAINER_PREFIX) === 0) {
      service = service.replace(SERVICE_CONTAINER_PREFIX, '');
    }

    // Do not launch dialog if this service does not need repair.
    if (!$('#healthStatusDisplay').healthDisplay('needsRepair', service)) {
      return;
    }

    function repairServiceCallback(response) {
      $('#healthStatusDisplay').healthDisplay('markStale', response.service);
    }

    rpcActionInfo(service, healthcheck, action, function(response) {
      if (isEmpty(response.args) && isEmpty(response.kwargs)) {
        rpcRepairService(service, healthcheck, action,
                         [], {}, repairServiceCallback);
        return;
      }

      var dialog = new ActionRepairDialog(service, response);
      dialog.submitHandler = function(service, action, args, kwargs) {
        rpcRepairService(service, healthcheck, action,
                         args, kwargs, repairServiceCallback);
      };
      dialog.open();
    });
  });
});