import { ckn } from "@ckn-technology/core";
import { Component } from "@ckn-technology/ui";
class IssueList extends Component {
constructor() {
super();
this.createdAtFrom = new Date().addDays(-7).dateDataFormat();
this.createdAtTo = new Date().addDays(1).dateDataFormat();
this.searchText = "";
this.results = [];
this.originalList = [];
}
async onInitializing() {
await this.reloadDataFromBackend();
}
async reloadDataFromBackend() {
const result = await ckn.api.post("/issue/list", {
createdAtFrom: this.createdAtFrom,
createdAtTo: this.createdAtTo,
searchText: this.searchText,
});
let index = 1;
this.results = [];
for (let issue of result.issues || []) {
this.results.push({
id: issue.id,
index: index++,
resourceName: issue.resourceName,
reportedDate: issue.reportedDate,
status: issue.status,
});
}
this.originalList = this.results;
}
async filter() {
this.createdAtFrom = new Date(this.createdAtFrom).dateDataFormat();
this.createdAtTo = new Date(this.createdAtTo).dateDataFormat();
let i = 1;
this.results = this.originalList
.where(c => c.reportedDate >= this.createdAtFrom
&& c.reportedDate <= this.createdAtTo)
.where(c => c.index = i++);
}
async searchResourceIssueHistory(target) {
if (target != null) this.searchText = $(target).val();
// apply text filtering on this.originalList + date range...
}
async exportTableToExcel() {
let date = new Date().dateDataFormat();
const table = document.getElementById("issueTable");
const workbook = XLSX.utils.table_to_book(table, { sheet: "Issues" });
XLSX.writeFile(workbook, `issue-list-(${date}).xlsx`);
}
async onTemplateBuilding() {
return /*html*/`
<div>
<h3>Issue List</h3>
<div class="filters">
<input type="date" @value="{{this.createdAtFrom}}">
<input type="date" @value="{{this.createdAtTo}}">
<input type="text"
placeholder="Search..."
@value="{{this.searchText}}">
<button click()="{{this.filter()}}">Filter</button>
<button click()="{{this.exportTableToExcel()}}">
Export
</button>
</div>
<table id="issueTable">
<thead>
<tr>
<th>#</th>
<th>Resource</th>
<th>Date</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr :for="{{issue of this.results}}">
<td>{{issue.index}}</td>
<td>{{issue.resourceName}}</td>
<td>{{issue.reportedDate}}</td>
<td>{{issue.status}}</td>
</tr>
</tbody>
</table>
</div>
`;
}
}
export { IssueList };
This is the typical way you build screens/pages with
@ckn-technology/ui:
state in properties, data load with ckn.api, table rendering
with :for, filtering via events, and export/utility actions with
normal JavaScript.