Skip to content

Commit

Permalink
Delete last widget on page deletes page
Browse files Browse the repository at this point in the history
  • Loading branch information
mxtommy committed Apr 18, 2020
1 parent a6e7469 commit d5d0af1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
### V0.1.13
* add ngcanvasgauges and new modern theme (thanks godind!)
* new Theme change event allowing widgets to subscribe to theme changes (thanks godind!)
* Fix Historical Graph color change on theme update
* Historical Graph color change on theme update
* Update WidgetString to use canvas like numeric widget for dynamic font size
* Latitude/Longitude Unit format
* Load / Save config from server!
* Notifications service
* Deleting the last widget in a page deletes the page!

### V0.1.12
* iFrame to embed something in kip
Expand Down
58 changes: 36 additions & 22 deletions src/app/layout-splits.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,30 +206,44 @@ export class LayoutSplitsService {
this.updateSplit(splitSetUUID);

} else {
if (this.isRootSplit(splitSetUUID)) {
console.log('Tried deleting last widget in root');
//delete Area
let areaIndex = this.splitSets[splitIndex].splitAreas.findIndex(w => w.uuid == areaUUID);
if (areaIndex < 0) { return null; } // not found?
this.splitSets[splitIndex].splitAreas.splice(areaIndex,1);
// add a new Blank widget
let newUUID = this.WidgetManagerService.newWidget();
this.splitSets[splitIndex].splitAreas.push({uuid: newUUID, type: 'widget', size:100});

this.updateSplit(splitSetUUID);
return;
}
// We're the last area in the splitset, so delete the whole splitset
this.WidgetManagerService.deleteWidget(areaUUID);

// find parent split :|
let parentIndex = this.splitSets.findIndex( sSet => sSet.uuid == this.splitSets[splitIndex].parentUUID);
let parentUUID = this.splitSets[parentIndex].uuid;

//delete this splitset...
this.splitSets.splice(splitIndex, 1);
// we don't delete the sub, otherwise might get areas

this.deleteArea(parentUUID, splitSetUUID);
if (this.isRootSplit(splitSetUUID)) {
// We're the rootsplit, bye bye page
console.log('Deleting last split in root');

//delete this splitset...
this.splitSets.splice(splitIndex, 1);

//remove from rootUUIDs
let rootIndex = this.rootUUIDs.findIndex( uuid => uuid == splitSetUUID);
this.rootUUIDs.splice(rootIndex,1);
this.saveRootUUIDs();

if (this.rootUUIDs.length <= 0) {
// no more roots, we need at least one
console.log("deleted last page");
this.newRootSplit();
this.setActiveRootIndex(0);
}

this.nextRoot();
} else {
// we're not the root, so find parent split and clear there.

// find parent split,
let parentIndex = this.splitSets.findIndex( sSet => sSet.uuid == this.splitSets[splitIndex].parentUUID);
let parentUUID = this.splitSets[parentIndex].uuid;

//delete this splitset...
this.splitSets.splice(splitIndex, 1);
// we don't delete the sub, otherwise might get areas

this.deleteArea(parentUUID, splitSetUUID);
}


}


Expand Down

0 comments on commit d5d0af1

Please sign in to comment.