reduced redundant code
This commit is contained in:
parent
47b238a233
commit
79db56cb1d
@ -13,6 +13,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderPage(data) {
|
function renderPage(data) {
|
||||||
|
let doc = pageManager.document;
|
||||||
|
|
||||||
let iconName = {
|
let iconName = {
|
||||||
"post": "file text",
|
"post": "file text",
|
||||||
"user": "users",
|
"user": "users",
|
||||||
@ -25,16 +27,17 @@
|
|||||||
"comment": "留言總數"
|
"comment": "留言總數"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let overviewSegment = create('div', "ts primary segment");
|
||||||
|
let blogNameContainer = create('div', "ts large header");
|
||||||
|
let cardContainer = create('div', "ts stackable three cards");
|
||||||
let statTemplate = `<div class="ts left aligned statistic"><div class="value">{{ value }}</div><div class="label">{{ label }}</div></div>`
|
let statTemplate = `<div class="ts left aligned statistic"><div class="value">{{ value }}</div><div class="label">{{ label }}</div></div>`
|
||||||
|
|
||||||
let cardContainer = create('div'); cardContainer.className = "ts stackable three cards";
|
|
||||||
|
|
||||||
for (let key in data) {
|
for (let key in data) {
|
||||||
if (Object.keys(statLabel).indexOf(key) != -1) {
|
if (Object.keys(statLabel).indexOf(key) != -1) {
|
||||||
let card = create('div'); card.className = "ts card";
|
let card = create('div', "ts card");
|
||||||
let content = create('div'); content.className = "content";
|
let content = create('div', "content");
|
||||||
let symbol = create('div'); symbol.className = "symbol";
|
let symbol = create('div', "symbol");
|
||||||
let icon = create('i'); icon.className = `${iconName[key]} icon`;
|
let icon = create('i', `${iconName[key]} icon`);
|
||||||
|
|
||||||
content.innerHTML = statTemplate.replace("{{ value }}", data[key]).replace("{{ label }}", statLabel[key]);
|
content.innerHTML = statTemplate.replace("{{ value }}", data[key]).replace("{{ label }}", statLabel[key]);
|
||||||
symbol.appendChild(icon);
|
symbol.appendChild(icon);
|
||||||
@ -44,19 +47,24 @@
|
|||||||
cardContainer.appendChild(card);
|
cardContainer.appendChild(card);
|
||||||
} else if (key === "name") {
|
} else if (key === "name") {
|
||||||
// blog name
|
// blog name
|
||||||
|
blogNameContainer.textContent = data[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// finish up
|
// finish up
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
pageManager.document.innerHTML = "";
|
doc.innerHTML = "";
|
||||||
pageManager.document.appendChild(cardContainer);
|
overviewSegment.appendChild(blogNameContainer);
|
||||||
|
overviewSegment.appendChild(cardContainer);
|
||||||
|
doc.appendChild(overviewSegment);
|
||||||
pageManager.setLoaderState(false)
|
pageManager.setLoaderState(false)
|
||||||
}, 500);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function create(tag) {
|
function create(tag, className="") {
|
||||||
return document.createElement(tag);
|
let el = document.createElement(tag);
|
||||||
|
el.className = className;
|
||||||
|
return el;
|
||||||
}
|
}
|
||||||
|
|
||||||
pageManager.register("statistics", function () {
|
pageManager.register("statistics", function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user