Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine groups API - fixes #2939 #3101

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/controllers/groups_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function build(): express.Router {
Things.getThingDescriptions(request.get('Host'), request.secure)
.then((things) => {
const filteredThings = Array.from(things.values()).filter((thing) => {
return thing.group_id == id;
return thing.groupId == id;
});
response.status(200).json(filteredThings);
})
Expand Down
16 changes: 8 additions & 8 deletions src/models/thing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export interface ThingDescription {
iconData: IconData;
security: string;
securityDefinitions: SecurityDefinition;
group_id: string | null;
groupId: string | null;
}

interface IconData {
Expand Down Expand Up @@ -116,7 +116,7 @@ export default class Thing extends EventEmitter {

private iconHref: string | null;

private group_id: string | null;
private groupId: string | null;

/**
* Thing constructor.
Expand Down Expand Up @@ -369,7 +369,7 @@ export default class Thing extends EventEmitter {
this.setIcon(description.iconData, false);
}

this.group_id = description.group_id || null;
this.groupId = description.groupId || null;
}

getId(): string {
Expand All @@ -385,7 +385,7 @@ export default class Thing extends EventEmitter {
}

getGroup(): string | null {
return this.group_id;
return this.groupId;
}

getHref(): string {
Expand Down Expand Up @@ -552,11 +552,11 @@ export default class Thing extends EventEmitter {
/**
* Set the group for a Thing in the overview.
*
* @param {string} group_id ID of the group
* @param {string} groupId ID of the group
* @return {Promise} A promise which resolves with the description set.
*/
setGroup(group_id: string | null): Promise<ThingDescription> {
this.group_id = group_id;
setGroup(groupId: string | null): Promise<ThingDescription> {
this.groupId = groupId;
return Database.updateThing(this.id, this.getDescription()).then((descr) => {
return descr;
});
Expand Down Expand Up @@ -664,7 +664,7 @@ export default class Thing extends EventEmitter {
layoutIndex: this.layoutIndex,
selectedCapability: this.selectedCapability,
iconHref: this.iconHref,
group_id: this.group_id,
groupId: this.groupId,
} as ThingDescription;

if (typeof reqHost !== 'undefined') {
Expand Down
24 changes: 12 additions & 12 deletions src/models/things.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,16 +361,16 @@ class Things extends EventEmitter {
* Set the group for a Thing in the overview.
*
* @param {number} thing The thing.
* @param {string} group_id ID of the group
* @param {string} groupId ID of the group
* @return {Promise} A promise which resolves with the description set.
*/
async setThingGroup(thing: Thing, group_id: string | null, emitModified = true): Promise<void> {
if (!group_id) {
group_id = null;
async setThingGroup(thing: Thing, groupId: string | null, emitModified = true): Promise<void> {
if (!groupId) {
groupId = null;
}

await this.setThingLayoutIndex(thing, Infinity, false);
await thing.setGroup(group_id);
await thing.setGroup(groupId);
const index =
Array.from(this.things.values()).filter((t) => t.getGroup() == thing.getGroup()).length - 1;
await thing.setLayoutIndex(index);
Expand All @@ -384,19 +384,19 @@ class Things extends EventEmitter {
* Set the group and layout index for a Thing in the overview.
*
* @param {number} thing The thing.
* @param {string} group_id ID of the group
* @param {string} groupId ID of the group
* @param {number} index The new layout index.
* @return {Promise} A promise which resolves with the description set.
*/
async setThingGroupAndLayoutIndex(
thing: Thing,
group_id: string | null,
groupId: string | null,
index: number
): Promise<void> {
if (!group_id) {
group_id = null;
if (!groupId) {
groupId = null;
}
await this.setThingGroup(thing, group_id, false);
await this.setThingGroup(thing, groupId, false);
await this.setThingLayoutIndex(thing, index, false);
this.emit(Constants.LAYOUT_MODIFIED);
}
Expand All @@ -415,13 +415,13 @@ class Things extends EventEmitter {
}

const index = thing.getLayoutIndex();
const group_id = thing.getGroup();
const groupId = thing.getGroup();

thing.remove();
this.things.delete(id);

Array.from(this.things.values())
.filter((t) => t.getGroup() == group_id)
.filter((t) => t.getGroup() == groupId)
.forEach((t) => {
if (t.getLayoutIndex() > index) {
t.setLayoutIndex(t.getLayoutIndex() - 1);
Expand Down
2 changes: 1 addition & 1 deletion static/js/models/thing-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ThingModel extends Model {
}

// Parse group id of Thing
this.group_id = description.group_id;
this.groupId = description.groupId;

// Parse properties and events URLs
for (const form of description.forms) {
Expand Down
6 changes: 3 additions & 3 deletions static/js/schema-impl/capability/thing.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class Thing {
this.container = document.getElementById('floorplan');
this.x = description.floorplanX;
this.y = description.floorplanY;
} else if (this.model.group_id) {
this.container = document.querySelector(`#group-${this.model.group_id}`);
} else if (this.model.groupId) {
this.container = document.querySelector(`#group-${this.model.groupId}`);
} else {
this.container = document.getElementById('things');
}
Expand Down Expand Up @@ -712,7 +712,7 @@ class Thing {
}

const dragNodeId = Utils.unescapeHtml(dragNode.id).replace(/^thing-/, '');
API.setThingGroupAndLayoutIndex(dragNodeId, this.model.group_id, dropIndex)
API.setThingGroupAndLayoutIndex(dragNodeId, this.model.groupId, dropIndex)
.then(() => {
App.gatewayModel.refreshThings();
})
Expand Down
Loading