@brightspace-hmc/siren-sdk
Advanced tools
Comparing version 2.65.0 to 2.66.0
{ | ||
"name": "@brightspace-hmc/siren-sdk", | ||
"version": "2.65.0", | ||
"version": "2.66.0", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "", |
@@ -1,4 +0,5 @@ | ||
import { Actions } from '../../hypermedia-constants.js'; | ||
import { Actions, Classes } from '../../hypermedia-constants.js'; | ||
import { Entity } from '../../es6/Entity.js'; | ||
import { performSirenAction } from '../../es6/SirenAction.js'; | ||
import { RestrictedTopicCollectionEntity } from './RestrictedTopicCollectionEntity.js'; | ||
@@ -44,2 +45,61 @@ export class GroupSectionRestrictionActionsEntity extends Entity { | ||
} | ||
restrictedTopicCollection() { | ||
if (!this._entity) return null; | ||
const subEntity = this._entity.getSubEntityByClass(Classes.discussions.restrictedTopic); | ||
if (!subEntity) { | ||
return null; | ||
} | ||
return new RestrictedTopicCollectionEntity(subEntity); | ||
} | ||
canToggleGroupsRestrictedTopic() { | ||
if (!this._entity) return null; | ||
const subEntity = this._entity.getSubEntityByClass(Classes.discussions.restrictedTopic); | ||
return subEntity && subEntity.hasActionByName(Actions.discussions.groupSectionRestrictions.toggleGroupsRestrictedTopic); | ||
} | ||
_formatToggleGroupsRestrictedTopicAction(toggleGroupIds) { | ||
if (!toggleGroupIds) return; | ||
if (!this.canToggleGroupsRestrictedTopic()) return; | ||
const subEntity = this._entity.getSubEntityByClass(Classes.discussions.restrictedTopic); | ||
const action = subEntity.getActionByName(Actions.discussions.groupSectionRestrictions.toggleGroupsRestrictedTopic); | ||
const fields = toggleGroupIds.map(id => { | ||
return { name: 'toggleGroupIds', value: id }; | ||
}); | ||
return { action, fields }; | ||
} | ||
_restrictedTopicToggle(selectedIds) { | ||
const outputToggle = []; | ||
const oldRestrictedTopicCollection = this.restrictedTopicCollection().getRestrictedTopics(); | ||
if (!oldRestrictedTopicCollection) return; | ||
const newRestrictedTopicMap = {}; | ||
selectedIds.forEach(ids => { | ||
newRestrictedTopicMap[ids] = ids; | ||
}); | ||
oldRestrictedTopicCollection.forEach(oldTopic => { | ||
const oldTopicId = oldTopic.id(); | ||
const newIsSelected = newRestrictedTopicMap[oldTopicId] !== undefined; | ||
if (oldTopic.isSelected() !== newIsSelected) { | ||
outputToggle.push(oldTopicId); | ||
} | ||
}); | ||
return outputToggle; | ||
} | ||
async toggleGroupsRestrictedTopic(selectedIds) { | ||
if (!selectedIds) return; | ||
if (!this.canToggleGroupsRestrictedTopic()) return; | ||
const toggleGroupIds = this._restrictedTopicToggle(selectedIds); | ||
const sirenAction = this._formatToggleGroupsRestrictedTopicAction(toggleGroupIds); | ||
if (!sirenAction) return; | ||
const { action, fields } = sirenAction; | ||
performSirenAction(this._token, action, fields); | ||
} | ||
} |
@@ -394,2 +394,3 @@ export const Rels = { | ||
section: 'section', | ||
selected: 'selected', | ||
allGroups: 'all-groups', | ||
@@ -737,3 +738,4 @@ allSections: 'all-sections' | ||
setToRestrictedTopic: 'set-to-restricted-topic', | ||
setToRestrictedThreads: 'set-to-restricted-threads' | ||
setToRestrictedThreads: 'set-to-restricted-threads', | ||
toggleGroupsRestrictedTopic: 'toggle-groups-restricted-topic' | ||
} | ||
@@ -740,0 +742,0 @@ }, |
379742
111
10463