1 | <?php |
||
2 | |||
3 | use App\Models\AlertRule; |
||
4 | use App\Models\AlertTemplate; |
||
5 | use App\Models\AlertTemplateMap; |
||
6 | |||
7 | $no_refresh = true; |
||
8 | |||
9 | require_once 'includes/html/modal/alert_template.inc.php'; |
||
10 | require_once 'includes/html/modal/delete_alert_template.inc.php'; |
||
11 | ?> |
||
12 | <div class="table-responsive"> |
||
13 | <table id="templatetable" class="table table-hover table-condensed" width="100%"> |
||
14 | <thead> |
||
15 | <tr> |
||
16 | <th data-column-id="id" data-searchable="false" data-identifier="true" data-type="numeric">#</th> |
||
17 | <th data-column-id="templatename">Name</th> |
||
18 | <th data-column-id="alert_rules" data-searchable="false" data-formatter="alert_rules">Alert Rules</th> |
||
19 | <th data-column-id="actions" data-searchable="false" data-formatter="commands">Action</th> |
||
20 | <th data-column-id="old_template" data-searchable="false" data-visible="false">Old template</th> |
||
21 | </tr> |
||
22 | </thead> |
||
23 | <tbody> |
||
24 | <?php |
||
25 | $full_query = AlertTemplate::select('id', 'name', 'template')->get(); |
||
26 | |||
27 | foreach ($full_query as $template) { |
||
28 | $single_template = ['name' => $template->name, |
||
29 | 'template' => $template->template, |
||
30 | ]; |
||
31 | |||
32 | if ($template->name == 'Default Alert Template') { |
||
33 | $default_tplid = $template->id; |
||
34 | $single_template['id'] = 0; |
||
35 | $single_template['alert_rules'] = AlertRule::whereNotIn('id', AlertTemplateMap::pluck('alert_rule_id')) |
||
36 | ->select('id', 'name') |
||
37 | ->orderBy('name') |
||
38 | ->get(); |
||
39 | } else { |
||
40 | $single_template['id'] = $template->id; |
||
41 | $single_template['alert_rules'] = $template->alert_rules; |
||
42 | } |
||
43 | |||
44 | $templates[] = $single_template; |
||
45 | } |
||
46 | |||
47 | $template_ids = array_column($templates, 'id'); |
||
48 | array_multisort($templates, SORT_ASC, $template_ids); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
49 | foreach ($templates as $template) { |
||
50 | $old_template = strpos($template['template'], '{/if}') !== false ? '1' : ''; |
||
51 | echo '<tr data-row-id="' . $template['id'] . '"> |
||
52 | <td>' . $template['id'] . '</td> |
||
53 | <td>' . $template['name'] . '</td> |
||
54 | <td>' . json_encode($template['alert_rules']) . '</td> |
||
55 | <td>' . $old_template . '</td> |
||
56 | </tr>'; |
||
57 | } |
||
58 | |||
59 | ?> |
||
60 | </tbody> |
||
61 | </table> |
||
62 | </div> |
||
63 | <script> |
||
64 | $(document).ready(function() { |
||
65 | var grid = $('#templatetable').bootgrid({ |
||
66 | rowCount: [50, 100, 250, -1], |
||
67 | templates: { |
||
68 | header: '<div id="{{ctx.id}}" class="{{css.header}}"> \ |
||
69 | <div class="row"> \ |
||
70 | <?php if (Auth::user()->hasGlobalAdmin()) { ?> |
||
71 | <div class="col-sm-8 actionBar"> \ |
||
72 | <span class="pull-left"> \ |
||
73 | <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#alert-template" data-template_id="">Create new alert template</button> \ |
||
74 | </span> \ |
||
75 | </div> \ |
||
76 | <div class="col-sm-4 actionBar"><p class="{{css.search}}"></p><p class="{{css.actions}}"></p></div></div></div>' |
||
77 | <?php } else { ?> |
||
78 | <div class="actionBar"><p class="{{css.search}}"></p><p class="{{css.actions}}"></p></div></div></div>' |
||
79 | |||
80 | <?php } ?> |
||
81 | }, |
||
82 | formatters: { |
||
83 | "commands": function(column, row) { |
||
84 | var response = ''; |
||
85 | //FIXME remove Deprecated template |
||
86 | if (row.old_template == "1") { |
||
87 | response = "<button type='button' class='btn btn-xs btn-warning' data-content=' class='btn btn-xs btn-warning' data-content='><i class='fa fa-exclamation-triangle' title='This is a legacy template and needs converting, please edit this template and click convert then save'><i class='fa fa-exclamation-triangle'></i></button> "; |
||
88 | } |
||
89 | if(row.id == 0) { |
||
90 | response = response + "<button type=\"button\" class=\"btn btn-xs btn-primary command-edit\" data-toggle='modal' data-target='#alert-template' data-template_id=\"" + row.id + "\" data-template_action='edit' name='edit-alert-template'><i class=\"fa fa-pencil\" aria-hidden=\"true\"></i></button> " + "<button type=\"button\" class=\"btn btn-xs btn-danger command-delete\" disabled=\"disabled\"><i class=\"fa fa-trash-o\" aria-hidden=\"true\"></i></button>"; |
||
91 | } else { |
||
92 | response = response + "<button type=\"button\" class=\"btn btn-xs btn-primary command-edit\" data-toggle='modal' data-target='#alert-template' data-template_id=\"" + row.id + "\" data-template_action='edit' name='edit-alert-template'><i class=\"fa fa-pencil\" aria-hidden=\"true\"></i></button> " + "<button type=\"button\" class=\"btn btn-xs btn-danger command-delete\" data-toggle=\"modal\" data-target='#confirm-delete-alert-template' data-template_id=\"" + row.id + "\" name='delete-alert-template'><i class=\"fa fa-trash-o\" aria-hidden=\"true\"></i></button>"; |
||
93 | } |
||
94 | return response; |
||
95 | }, |
||
96 | "alert_rules": function(column, row) { |
||
97 | var response = ''; |
||
98 | alert_rules = JSON.parse(row.alert_rules); |
||
99 | $.each(alert_rules, function(_, alert_rule) { |
||
100 | response = response + alert_rule.name + '<br>'; |
||
101 | }); |
||
102 | return response; |
||
103 | }, |
||
104 | }, |
||
105 | }).on("loaded.rs.jquery.bootgrid", function() { |
||
106 | /* Executes after data is loaded and rendered */ |
||
107 | grid.find(".command-edit").on("click", function(e) { |
||
108 | var localtmpl_id = $(this).data("template_id"); |
||
109 | if(localtmpl_id == 0) { |
||
110 | $('#default_template').val("1"); |
||
111 | $('#template_id').val(<?=$default_tplid?>); |
||
112 | } else { |
||
113 | $('#default_template').val("0"); |
||
114 | $('#template_id').val(localtmpl_id); |
||
115 | } |
||
116 | $("#alert-template").modal('show'); |
||
117 | }).end().find(".command-delete").on("click", function(e) { |
||
118 | $('#template_id').val($(this).data("template_id")); |
||
119 | $('#confirm-delete-alert-template').modal('show'); |
||
120 | }); |
||
121 | }); |
||
122 | }); |
||
123 | </script> |
||
124 |