in traffic_portal/app/src/common/modules/table/agGrid/CommonGridController.js [111:314]
filter: parseInt(values[1], 10),
type: "equals"
}
}
if (isNaN(filterModel.condition1.filter) || isNaN(filterModel.condition2.filter)) {
continue;
}
}
break;
case "date":
const date = new Date(values[0]);
if (Number.isNaN(date.getTime())) {
continue;
}
const pad = num => String(num).padStart(2,"0");
filterModel = {
dateFrom: `${date.getUTCFullYear()}-${pad(date.getUTCMonth()+1)}-${pad(date.getUTCDate())} ${pad(date.getUTCHours())}:${pad(date.getUTCMinutes())}:${pad(date.getUTCSeconds())}`,
type: "equals"
}
break;
}
filter.setModel(filterModel);
filter.applyModel();
}
}
/**
* @param {*} $scope
* @param {import("angular").IDocumentService} $document
* @param {*} $state
* @param {import("../../../models/UserModel")} userModel
* @param {import("../../../service/utils/DateUtils")} dateUtils
*/
let CommonGridController = function ($scope, $document, $state, userModel, dateUtils) {
this.entry = null;
this.quickSearch = "";
this.pageSize = 100;
this.showMenu = false;
/**
* @type {{
* bottom?: string | 0;
* left: string | 0;
* right?: string | 0;
* top: string | 0;
* }}
*/
this.menuStyle = {
left: 0,
top: 0
};
this.mouseDownSelectionText = "";
// Bound Variables
/** @type string */
this.tableTitle = "";
/** @type string */
this.tableName = "";
/** @type CGC.GridSettings */
this.options = {};
/** @type any */
this.gridOptions = {};
/** @type any[] */
this.columns = [];
/** @type string[] */
this.sensitiveColumns = [];
/** @type any[] */
this.data = [];
/** @type any[] */
this.selectedData = [];
/** @type any */
this.defaultData = {};
/** @type CGC.DropDownOption[] */
this.dropDownOptions = [];
/** @type CGC.ContextMenuOption[] */
this.contextMenuOptions = [];
/** @type CGC.TitleButton */
this.titleButton = {};
/** @type CGC.TitleBreadCrumbs */
this.breadCrumbs = [];
function HTTPSCellRenderer() {}
HTTPSCellRenderer.prototype.init = function(params) {
this.eGui = document.createElement("a");
this.eGui.href = "https://" + params.value;
this.eGui.setAttribute("class", "link");
this.eGui.setAttribute("target", "_blank");
this.eGui.textContent = params.value;
};
HTTPSCellRenderer.prototype.getGui = function() {return this.eGui;};
// browserify can't handle classes...
function SSHCellRenderer() {}
SSHCellRenderer.prototype.init = function(params) {
this.eGui = document.createElement("a");
this.eGui.href = "ssh://" + userModel.user.username + "@" + params.value;
this.eGui.setAttribute("class", "link");
this.eGui.textContent = params.value;
};
SSHCellRenderer.prototype.getGui = function() {return this.eGui;};
function CheckCellRenderer() {}
CheckCellRenderer.prototype.init = function(params) {
this.eGui = document.createElement("i");
if (params.value === null || params.value === undefined) {
return;
}
this.eGui.setAttribute("aria-hidden", "true");
this.eGui.setAttribute("title", String(params.value));
this.eGui.classList.add("fa", "fa-lg");
if (params.value) {
this.eGui.classList.add("fa-check");
} else {
this.eGui.classList.add("fa-times");
}
};
CheckCellRenderer.prototype.getGui = function() {return this.eGui;};
function UpdateCellRenderer() {}
UpdateCellRenderer.prototype.init = function(params) {
this.eGui = document.createElement("i");
this.eGui.setAttribute("aria-hidden", "true");
this.eGui.setAttribute("title", String(params.value));
this.eGui.classList.add("fa", "fa-lg");
if (params.value) {
this.eGui.classList.add("fa-clock-o");
} else {
this.eGui.classList.add("fa-check");
}
};
UpdateCellRenderer.prototype.getGui = function() {return this.eGui;};
function defaultTooltip(params) {
return params.value;
}
function dateCellFormatterRelative(params) {
return params.value ? dateUtils.getRelativeTime(params.value) : params.value;
}
function dateCellFormatterUTC(params) {
return params.value ? params.value.toUTCString() : params.value;
}
this.hasContextItems = function() {
return this.contextMenuOptions.length > 0;
};
this.hasSensitiveColumns = function() {
return this.sensitiveColumns.length > 0;
}
/**
* @param {string} colID
*/
this.isSensitive = function(colID) {
return this.sensitiveColumns.includes(colID);
}
this.sensitiveColumnsShown = false;
this.toggleSensitiveFields = function() {
if (this.sensitiveColumnsShown) {
return;
}
for (const col of this.gridOptions.columnApi.getAllColumns()) {
const id = col.getColId();
if (this.isSensitive(id)) {
this.gridOptions.columnApi.setColumnVisible(id, false);
}
}
};
this.getColumns = () => {
/** @type {{colId: string}[]} */
const cols = this.gridOptions.columnApi.getAllColumns();
if (!this.hasSensitiveColumns || this.sensitiveColumnsShown) {
return cols;
}
return cols.filter(c => !this.isSensitive(c.colId));
}
this.$onInit = () => {
const tableName = this.tableName;
if (this.defaultData !== undefined) {
this.entry = this.defaultData;
}
for(let i = 0; i < this.columns.length; ++i) {
if (this.columns[i].filter === "agDateColumnFilter") {
if (this.columns[i].relative) {
this.columns[i].tooltipValueGetter = dateCellFormatterRelative;
this.columns[i].valueFormatter = dateCellFormatterRelative;
}
else {
this.columns[i].tooltipValueGetter = dateCellFormatterUTC;
this.columns[i].valueFormatter = dateCellFormatterUTC;
}
} else if (this.columns[i].filter === 'arrayTextColumnFilter') {
this.columns[i].filter = 'agTextColumnFilter'
this.columns[i].filterParams = {
textCustomComparator: (filter, value, filterText) => {