index.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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>
  22. <a :href="'/schedule.html?id=' + item.id">${ item.id }</a>
  23. </md-table-cell>
  24. <md-table-cell md-label="enabled" md-sort-by="enabled">
  25. <md-icon v-if="item.enabled">check_box</md-icon>
  26. <md-icon v-if="!item.enabled">check_box_outline_blank</md-icon>
  27. </md-table-cell>
  28. <md-table-cell md-label="schedule" md-sort-by="schedule">
  29. <a :href="'/schedule.html?id=' + item.id"><strong>${ item.title }</strong></a>
  30. <br />
  31. <span>
  32. <md-icon>link</md-icon>
  33. <a :href="item.url" target="_new">${ prettifyLink(item) }</a>
  34. <md-tooltip md-direction="bottom">${ item.url }</md-tooltip>
  35. </span>
  36. </md-table-cell>
  37. <md-table-cell md-label="trigger" md-sort-by="trigger">
  38. ${ triggerString(item) }
  39. <br />
  40. last check: ${ prettifyLastCheck(item) }
  41. </md-table-cell>
  42. <md-table-cell md-label="actions" class="table-cell-left">
  43. <div class="md-layout md-alignment-top-left">
  44. <div class="md-layout-item md-medium-size-10 md-small-size-50">
  45. <md-button :href="'/history.html?id=' + item.id" class="md-icon-button md-primary md-dense" :md-ripple="false">
  46. <md-icon>history</md-icon>
  47. <md-tooltip md-direction="bottom">show history</md-tooltip>
  48. </md-button>
  49. </div>
  50. <div class="md-layout-item md-medium-size-10 md-small-size-50">
  51. <md-button class="md-icon-button md-primary md-dense" @click="runSchedule(item.id)" :md-ripple="false">
  52. <md-icon>play_circle_outline</md-icon>
  53. <md-tooltip md-direction="bottom">run now</md-tooltip>
  54. </md-button>
  55. </div>
  56. </div>
  57. </md-table-cell>
  58. </md-table-row>
  59. </md-table>
  60. </md-card-content>
  61. </md-card>
  62. </div>
  63. </div>
  64. </div>
  65. <script>
  66. Vue.use(VueMaterial.default);
  67. var app = new Vue({
  68. el: '#app',
  69. delimiters: ['${', '}'],
  70. data: {
  71. schedules: []
  72. },
  73. mounted: function() {
  74. this.getSchedules();
  75. },
  76. methods: {
  77. getSchedules: function() {
  78. var self = this;
  79. var data = axios.get('/api/schedules').then(function(response) {
  80. var schedules = [];
  81. _.forEach(response.data.schedules || {}, function(value, key) {
  82. value.id = key;
  83. schedules.push(value);
  84. });
  85. self.schedules = schedules;
  86. });
  87. },
  88. prettifyLink: function(item) {
  89. var link = item.url;
  90. if (!link) {
  91. return '';
  92. }
  93. if (link.length > 40) {
  94. link = link.substring(0, 40) + "\u2026";
  95. }
  96. return link;
  97. },
  98. prettifyLastCheck: function(item) {
  99. var last = (item.last_history && item.last_history.message) || '';
  100. return last.substring(0, last.indexOf('.'));
  101. },
  102. triggerString: function(item) {
  103. if (item.trigger == 'cron') {
  104. return 'cron: ' + item.cron_crontab;
  105. }
  106. if (item.trigger == 'interval') {
  107. var text = 'interval: ';
  108. var pieces = [];
  109. _.each(['weeks', 'days', 'hours', 'minutes', 'seconds'], function(value, key) {
  110. var int_val = item['interval_' + value];
  111. if (int_val && parseInt(int_val)) {
  112. var unit = value;
  113. if (int_val == 1) {
  114. unit = unit.slice(0, -1);
  115. }
  116. pieces.push('' + int_val + ' ' + unit);
  117. }
  118. });
  119. text = text + _.join(pieces, ', ');
  120. return text;
  121. }
  122. return '';
  123. },
  124. runSchedule: function(id) {
  125. var self = this;
  126. var data = axios.post('/api/schedules/' + id + '/run').then(function(response) {
  127. setTimeout(self.getSchedules, 2500);
  128. });
  129. }
  130. }
  131. });
  132. </script>
  133. {% end %}
  134. {% block style %}
  135. .table-cell-left > .md-table-cell-container {
  136. padding-left: 12px;
  137. }
  138. {% end %}