Skip to content

Commit

Permalink
Start data grid refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Sep 8, 2020
1 parent 521efbd commit 3b1a7a9
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 58 deletions.
54 changes: 28 additions & 26 deletions Server/wwwroot/scripts/Main/DataGrid.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 37 additions & 32 deletions Server/wwwroot/scripts/Main/DataGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,37 @@ import { ShowModal } from "../Shared/UI.js";


export const DataSource: Array<Device> = new Array<Device>();

export const FilterOptions = new class {
GroupFilter: string;
SearchFilter: string;
GroupFilter: string = "";
OnlineOnly: boolean = false;
SearchFilter: string = "";
ShowAllGroups: boolean = true;
};


export function AddOrUpdateDevices(devices: Array<Device>) {
DataSource.splice(0);

devices.sort((a, b) => {
if (a.IsOnline && !b.IsOnline) {
return -1;
}
else if (b.IsOnline && !a.IsOnline) {
return 1;
}
//if (a.IsOnline && !b.IsOnline) {
// return -1;
//}
//else if (b.IsOnline && !a.IsOnline) {
// return 1;
//}
return a.DeviceName.localeCompare(b.DeviceName, [], { sensitivity: "base" });
});

devices.forEach(x => {
AddOrUpdateDevice(x, false);
AddOrUpdateDevice(x);
});

ApplyFilter();
UpdateDeviceCounts();
}

export function AddOrUpdateDevice(device: Device, sortDevices: boolean) {
export function AddOrUpdateDevice(device: Device) {
var existingIndex = DataSource.findIndex(x => x.ID == device.ID);
if (existingIndex > -1) {
DataSource[existingIndex] = device;
Expand All @@ -43,21 +48,6 @@ export function AddOrUpdateDevice(device: Device, sortDevices: boolean) {
DataSource.push(device);
}

if (sortDevices) {
var selectedDevices = GetSelectedDevices();

UI.DeviceGrid.querySelectorAll(".record-row").forEach(row => {
row.remove();
});
AddOrUpdateDevices(DataSource);

selectedDevices.forEach(x => {
document.getElementById(x.ID).classList.add("row-selected");
});

return;
}

var tableBody = document.querySelector("#" + Main.UI.DeviceGrid.id + " tbody");
var recordRow = document.getElementById(device.ID);
if (recordRow == null) {
Expand Down Expand Up @@ -116,18 +106,29 @@ export function AddOrUpdateDevice(device: Device, sortDevices: boolean) {
AddConsoleOutput("Launching remote control on client device...");
HubConnection.Connection.invoke("RemoteControl", device.ID);
};

UpdateDeviceCounts();
}
export function ApplyFilter() {
for (var i = 0; i < DataSource.length; i++) {
var row = document.getElementById(DataSource[i].ID);
if (FilterOptions.ShowAllGroups ||
(DataSource[i].DeviceGroupID || "") == (FilterOptions.GroupFilter || "")) {
if (!FilterOptions.SearchFilter || deviceMatchesFilter(DataSource[i])) {
row.classList.remove("hidden");
continue;
}

if (FilterOptions.OnlineOnly && !DataSource[i].IsOnline) {
row.classList.add("hidden");
continue;
}

if (!FilterOptions.ShowAllGroups &&
(DataSource[i].DeviceGroupID || "") != (FilterOptions.GroupFilter || "")) {
row.classList.add("hidden");
continue;
}

if (deviceMatchesSearchFilter(DataSource[i])) {
row.classList.remove("hidden");
continue;
}

row.classList.add("hidden");
}
}
Expand Down Expand Up @@ -202,7 +203,11 @@ export function UpdateDeviceCounts() {
}
}

function deviceMatchesFilter(device: Device) {
function deviceMatchesSearchFilter(device: Device) {
if (!FilterOptions.SearchFilter) {
return true;
}

for (var key in device) {
var value = device[key];
if (!value) {
Expand Down

0 comments on commit 3b1a7a9

Please sign in to comment.