index.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. {% extends "base.html" %}
  2. {% block body %}
  3. <div id="app">
  4. <div class="md-layout">
  5. <div class="md-layout-item">
  6. <md-card id="main-card">
  7. <md-card-header>
  8. <div class="md-title">
  9. <md-button href="/" class="md-icon-button md-primary">
  10. <md-icon>home</md-icon>
  11. </md-button>
  12. Diffido
  13. <md-button href="/schedule.html" class="md-icon-button md-primary">
  14. <md-icon>add_circle_outline</md-icon>
  15. </md-button>
  16. </div>
  17. </md-card-header>
  18. <md-card-content>
  19. <md-table id="schedules-table" v-model="schedules">
  20. <md-table-row slot="md-table-row" slot-scope="{item}">
  21. <md-table-cell md-label="#" md-sort-by="id" md-numeric><a :href="'/schedule.html?id=' + item.id">${ item.id }</a></md-table-cell>
  22. <md-table-cell md-label="enabled" md-sort-by="enabled">
  23. <md-icon v-if="item.enabled">check_box</md-icon>
  24. <md-icon v-if="!item.enabled">check_box_outline_blank</md-icon>
  25. </md-table-cell>
  26. <md-table-cell md-label="title" md-sort-by="title"><a :href="'/schedule.html?id=' + item.id">${ item.title }</a></md-table-cell>
  27. <md-table-cell md-label="url" md-sort-by="url"><a :href="item.url" target="_new">${ item.url }</a></md-table-cell>
  28. <md-table-cell md-label="trigger" md-sort-by="trigger">${ triggerString(item) }</md-table-cell>
  29. <md-table-cell md-label="last check" md-sort-by="last_history">${ item.last_history && item.last_history.message }</md-table-cell>
  30. <md-table-cell md-label="history">
  31. <md-button :href="'/history.html?id=' + item.id" class="md-icon-button md-primary">
  32. <md-icon>history</md-icon>
  33. </md-button>
  34. </md-table-cell>
  35. <md-table-cell md-label="run now">
  36. <md-button class="md-icon-button md-primary" @click="runSchedule(item.id)">
  37. <md-icon>play_circle_outline</md-icon>
  38. </md-button>
  39. </md-table-cell>
  40. </md-table-row>
  41. </md-table>
  42. </md-card-content>
  43. </md-card>
  44. </div>
  45. </div>
  46. </div>
  47. <script>
  48. Vue.use(VueMaterial.default);
  49. var app = new Vue({
  50. el: '#app',
  51. delimiters: ['${', '}'],
  52. data: {
  53. schedules: []
  54. },
  55. mounted: function() {
  56. this.getSchedules();
  57. },
  58. methods: {
  59. getSchedules: function() {
  60. var self = this;
  61. var data = axios.get('/api/schedules').then(function(response) {
  62. var schedules = [];
  63. _.forEach(response.data.schedules || {}, function(value, key) {
  64. value.id = key;
  65. schedules.push(value);
  66. });
  67. self.schedules = schedules;
  68. });
  69. },
  70. triggerString: function(item) {
  71. if (item.trigger == 'cron') {
  72. return 'cron: ' + item.cron_crontab;
  73. }
  74. if (item.trigger == 'interval') {
  75. var text = 'interval: ';
  76. var pieces = [];
  77. _.each(['weeks', 'days', 'hours', 'minutes', 'seconds'], function(value, key) {
  78. var int_val = item['interval_' + value];
  79. if (int_val && parseInt(int_val)) {
  80. var unit = value;
  81. if (int_val == 1) {
  82. unit = unit.slice(0, -1);
  83. }
  84. pieces.push('' + int_val + ' ' + unit);
  85. }
  86. });
  87. text = text + _.join(pieces, ', ');
  88. return text;
  89. }
  90. return '';
  91. },
  92. runSchedule: function(id) {
  93. var self = this;
  94. var data = axios.post('/api/schedules/' + id + '/run').then(function(response) {
  95. setTimeout(self.getSchedules, 2500);
  96. });
  97. }
  98. }
  99. });
  100. </script>
  101. <style>
  102. body {
  103. background-color: white;
  104. padding: 6px;
  105. }
  106. .md-table {
  107. height: 80%;
  108. }
  109. </style>
  110. {% end %}