Skip to content

Commit 0dfff0e

Browse files
committed
add custom style sheet and translations
1 parent ed051fb commit 0dfff0e

File tree

4 files changed

+138
-44
lines changed

4 files changed

+138
-44
lines changed

language/en_GB/en_GB.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
23150 Compare devices :
2-
23151 Compare devices
2+
23151 Compare devices
3+
23152 (It may take a few seconds for the results to appear)
4+
23153 Main device to compare :
5+
23154 Other device to compare :

ms_compare_devices/create_XML.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
2-
2+
/*
3+
Generate xml structured string of a given device characteristics
4+
Returns a string
5+
*/
36
class DeviceXML {
47
function createXML($id) {
58
$sql = "select * from hardware where id=%s";

ms_compare_devices/ms_compare_devices.php

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,7 @@
3434
third party library
3535
3636
TODO :
37-
- improve selectors (what if 10+ devices)
38-
- table isnt displaying selected devices (?)
39-
40-
THINK HARDER :
41-
- autocompleted inputs vs dropdown selectors ?
42-
in case 1 vs 15 > cant display 15 selectors but two autocompleted inputs could do
43-
44-
- php-diff only displays diff 1vs1
45-
- php-diff table are not (yet) collapsable
37+
- allow multiple comparison
4638
*/
4739
require_once('create_XML.php');
4840
include ('/usr/share/ocsinventory-reports/ocsreports/vendor/jfcherng/php-diff/example/demo_base.php');
@@ -65,9 +57,9 @@
6557
color: #fb0;
6658
font-weight: normal;
6759
}";
68-
69-
echo DiffHelper::getStyleSheet();
70-
echo "</style><br><br>";
60+
// get custom css style sheet (columns width set to 50%)
61+
include '/usr/share/ocsinventory-reports/ocsreports/extensions/compare_devices/table_css/diff_table.css';
62+
echo "</style>";
7163

7264

7365
printEnTete($l->g(23150));
@@ -79,45 +71,29 @@
7971

8072

8173
echo open_form($form_name, '', 'enctype="multipart/form-data"', 'form-horizontal');
82-
echo '<div class="col col-md-10" >';
74+
echo '<div class="col col-md-12" >';
8375

84-
// req to select from
76+
// get selection of devices available for comparison
8577
$link = $_SESSION['OCS']["readServer"];
8678
$result = mysql2_query_secure("SELECT ID, DEVICEID FROM hardware WHERE deviceid <> '_SYSTEMGROUP_' AND deviceid <>'_DOWNLOADGROUP_'", $link);
8779
$result = mysqli_fetch_all($result, MYSQLI_ASSOC);
8880

89-
// prepare array for selection
81+
// deviceid will be displayed by selectors
9082
foreach ($result as $key => $value) {
9183
$display[$key] = $value['DEVICEID'];
9284
}
9385

9486
echo "<div>
9587
<div>";
96-
// select main device and other devices
97-
formGroup('select', 'main_device', 'Main device to compare :', '', '', '', '', $result, $display, "required");
98-
formGroup('select', 'other_device', 'Other device to compare :', '', '', '', '', $result, $display, "required");
99-
// submit values
100-
echo "<input type='submit' name='compare' id='compare' class='btn btn-success' value='Compare devices'>";
101-
echo "</div>
102-
</div>";
103-
104-
105-
// Display table of selected devices
106-
$list_fields = array(
107-
'ID' => 'ID',
108-
'DEVICE ID' => 'DEVICEID',
109-
);
110-
$list_fields['SUP'] = 'ID';
111-
$tab_options['LBL_POPUP']['SUP'] = 'TYPE_NAME';
112-
$default_fields = $list_fields;
113-
$list_col_cant_del = $list_fields;
114-
115-
$devices = array($result[$protectedPost['main_device']]['ID'], $result[$protectedPost['other_device']]['ID']);
116-
$in = implode(",", $devices);
117-
// query for table display
118-
$queryDetails = "SELECT ID, DEVICEID FROM hardware WHERE deviceid <> '_SYSTEMGROUP_' AND deviceid <>'_DOWNLOADGROUP_' AND id IN (".$in.")";
119-
ajaxtab_entete_fixe($list_fields, $default_fields, $tab_options, $list_col_cant_del);
88+
// selectors for main device and other devices
89+
formGroup('select', 'main_device', $l->g(23153), '', '', (int)$protectedPost['main_device'], '', $result, $display, "required");
90+
formGroup('select', 'other_device', $l->g(23154), '', '', (int)$protectedPost['other_device'], '', $result, $display, "required");
12091

92+
$time_delay_text = $l->g(23152);
93+
$button_text = $l->g(23151);
94+
echo "<br><p>$time_delay_text</p><br>";
95+
// submit values
96+
echo "<input type='submit' name='compare' id='compare' class='btn btn-success' value='$button_text'>";
12197
echo "</div>
12298
</div>";
12399
echo close_form();
@@ -126,11 +102,11 @@
126102
// TRAITEMENT XML -------------------------------------------------
127103
$xml = new DeviceXML();
128104

129-
// createXML acutally only creates xml structure in a string
105+
// get main device and other device as xml structured STRINGS
130106
$main_device = $xml->createXML($result[$protectedPost['main_device']]['ID']);
131107
$other_device = $xml->createXML($result[$protectedPost['other_device']]['ID']);
132108

133-
// demo the no-inline-detail diff
109+
// get differences between previously generated strings
134110
$inlineResult = DiffHelper::calculate(
135111
$main_device,
136112
$other_device,
@@ -140,7 +116,7 @@
140116
// detail levels : word, line, char, none
141117
['detailLevel' => 'none'] + $rendererOptions
142118
);
143-
echo "<div class='col col-md-10' style='overflow-y: auto; height:300px;'><br><br>$inlineResult</div>";
119+
echo "<div class='col col-md-12'><br><br>$inlineResult</div>";
144120
// -----------------------------------------------------------------
145121

146122
if (AJAX) {

table_css/diff_table.css

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* You can compile this by https://www.sassmeister.com with
3+
*
4+
* - dart-sass v1.18.0
5+
*/
6+
.diff-wrapper.diff {
7+
background: repeating-linear-gradient(-45deg, whitesmoke, whitesmoke 0.5em, #e8e8e8 0.5em, #e8e8e8 1em);
8+
border-collapse: collapse;
9+
border-spacing: 0;
10+
border: 1px solid black;
11+
color: black;
12+
empty-cells: show;
13+
font-family: monospace;
14+
font-size: 13px;
15+
width: 100%;
16+
word-break: break-all;
17+
}
18+
.diff-wrapper.diff th {
19+
font-weight: 700;
20+
}
21+
.diff-wrapper.diff td {
22+
vertical-align: baseline;
23+
width : 50%;
24+
}
25+
.diff-wrapper.diff td,
26+
.diff-wrapper.diff th {
27+
border-collapse: separate;
28+
border: none;
29+
padding: 1px 2px;
30+
background: #fff;
31+
}
32+
.diff-wrapper.diff td:empty:after,
33+
.diff-wrapper.diff th:empty:after {
34+
content: " ";
35+
visibility: hidden;
36+
}
37+
.diff-wrapper.diff td a,
38+
.diff-wrapper.diff th a {
39+
color: #000;
40+
cursor: inherit;
41+
pointer-events: none;
42+
}
43+
.diff-wrapper.diff thead th {
44+
background: #a6a6a6;
45+
border-bottom: 1px solid black;
46+
padding: 4px;
47+
text-align: left;
48+
}
49+
.diff-wrapper.diff tbody.skipped {
50+
border-top: 1px solid black;
51+
}
52+
.diff-wrapper.diff tbody.skipped td,
53+
.diff-wrapper.diff tbody.skipped th {
54+
display: none;
55+
}
56+
.diff-wrapper.diff tbody th {
57+
background: #cccccc;
58+
border-right: 1px solid black;
59+
text-align: right;
60+
vertical-align: top;
61+
width: 4em;
62+
}
63+
.diff-wrapper.diff tbody th.sign {
64+
background: #fff;
65+
border-right: none;
66+
padding: 1px 0;
67+
text-align: center;
68+
width: 1em;
69+
}
70+
.diff-wrapper.diff tbody th.sign.del {
71+
background: #fbe1e1;
72+
}
73+
.diff-wrapper.diff tbody th.sign.ins {
74+
background: #e1fbe1;
75+
}
76+
.diff-wrapper.diff.diff-html {
77+
white-space: pre-wrap;
78+
}
79+
.diff-wrapper.diff.diff-html.diff-combined .change.change-rep .rep {
80+
white-space: normal;
81+
}
82+
.diff-wrapper.diff.diff-html .change.change-eq .old,
83+
.diff-wrapper.diff.diff-html .change.change-eq .new {
84+
background: #fff;
85+
}
86+
.diff-wrapper.diff.diff-html .change .old {
87+
background: #fbe1e1;
88+
}
89+
.diff-wrapper.diff.diff-html .change .new {
90+
background: #e1fbe1;
91+
}
92+
.diff-wrapper.diff.diff-html .change .rep {
93+
background: #fef6d9;
94+
}
95+
.diff-wrapper.diff.diff-html .change .old.none,
96+
.diff-wrapper.diff.diff-html .change .new.none,
97+
.diff-wrapper.diff.diff-html .change .rep.none {
98+
background: transparent;
99+
cursor: not-allowed;
100+
}
101+
.diff-wrapper.diff.diff-html .change ins,
102+
.diff-wrapper.diff.diff-html .change del {
103+
font-weight: bold;
104+
text-decoration: none;
105+
}
106+
.diff-wrapper.diff.diff-html .change ins {
107+
background: #94f094;
108+
}
109+
.diff-wrapper.diff.diff-html .change del {
110+
background: #f09494;
111+
}
112+

0 commit comments

Comments
 (0)