Issue #83 - generate Container name
This commit is contained in:
parent
d745dd279c
commit
66b5f216ac
1 changed files with 24 additions and 2 deletions
|
@ -101,6 +101,28 @@ let Logic = {
|
||||||
}
|
}
|
||||||
return this._currentIdentity;
|
return this._currentIdentity;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
generateIdentityName() {
|
||||||
|
const defaultName = 'Container';
|
||||||
|
let ids = [];
|
||||||
|
|
||||||
|
// This loop populates the 'ids' array with all the already-used ids.
|
||||||
|
this._identities.forEach(identity => {
|
||||||
|
if (identity.name.startsWith(defaultName)) {
|
||||||
|
let id = parseInt(identity.name.substr(defaultName.length))
|
||||||
|
if (id) {
|
||||||
|
ids.push(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Here we find the first valid id.
|
||||||
|
for (let id = 1;; ++id) {
|
||||||
|
if (ids.indexOf(id) == -1) {
|
||||||
|
return defaultName + (id < 10 ? '0' : '') + id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// P_ONBOARDING_1: First page for Onboarding.
|
// P_ONBOARDING_1: First page for Onboarding.
|
||||||
|
@ -154,7 +176,7 @@ Logic.registerPanel(P_CONTAINERS_LIST, {
|
||||||
// This method is called when the object is registered.
|
// This method is called when the object is registered.
|
||||||
initialize() {
|
initialize() {
|
||||||
document.querySelector("#container-add-link").addEventListener("click", () => {
|
document.querySelector("#container-add-link").addEventListener("click", () => {
|
||||||
Logic.showPanel(P_CONTAINER_EDIT, {});
|
Logic.showPanel(P_CONTAINER_EDIT, { name: Logic.generateIdentityName() });
|
||||||
});
|
});
|
||||||
|
|
||||||
document.querySelector("#edit-containers-link").addEventListener("click", () => {
|
document.querySelector("#edit-containers-link").addEventListener("click", () => {
|
||||||
|
@ -316,7 +338,7 @@ Logic.registerPanel(P_CONTAINERS_EDIT, {
|
||||||
// This method is called when the object is registered.
|
// This method is called when the object is registered.
|
||||||
initialize() {
|
initialize() {
|
||||||
document.querySelector("#edit-containers-add-link").addEventListener("click", () => {
|
document.querySelector("#edit-containers-add-link").addEventListener("click", () => {
|
||||||
Logic.showPanel(P_CONTAINER_EDIT, {});
|
Logic.showPanel(P_CONTAINER_EDIT, { name: Logic.generateIdentityName() });
|
||||||
});
|
});
|
||||||
|
|
||||||
document.querySelector("#exit-edit-mode-link").addEventListener("click", () => {
|
document.querySelector("#exit-edit-mode-link").addEventListener("click", () => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue