diff --git a/src/main/java/org/olat/course/groupsandrights/BGRightsResourceNameRenderer.java b/src/main/java/org/olat/course/groupsandrights/BGRightsResourceNameRenderer.java new file mode 100644 index 0000000000000000000000000000000000000000..d90170c395c793600e10b755e9b1821d795cc5db --- /dev/null +++ b/src/main/java/org/olat/course/groupsandrights/BGRightsResourceNameRenderer.java @@ -0,0 +1,54 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.course.groupsandrights; + +import org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiCellRenderer; +import org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableComponent; +import org.olat.core.gui.render.Renderer; +import org.olat.core.gui.render.StringOutput; +import org.olat.core.gui.render.URLBuilder; +import org.olat.core.gui.translator.Translator; + +/** + * + * Initial date: 23 janv. 2018<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public class BGRightsResourceNameRenderer implements FlexiCellRenderer { + + @Override + public void render(Renderer renderer, StringOutput target, Object cellValue, + int row, FlexiTableComponent source, URLBuilder ubu, + Translator translator) { + + if(cellValue instanceof String) { + target.append((String)cellValue); + } else if(cellValue instanceof BGRightsRow) { + BGRightsRow rights = (BGRightsRow)cellValue; + if(rights.getResourceType() == BGRightsResourceType.businessGroup) { + target.append("<i class='o_icon o_icon-fw o_icon_group'> </i> "); + } else if(rights.getResourceType() == BGRightsResourceType.repositoryEntry) { + target.append("<i class='o_icon o_icon-fw o_CourseModule_icon'> </i> "); + } + target.append(rights.getName()); + } + } +} diff --git a/src/main/java/org/olat/course/groupsandrights/BGRightsResourceType.java b/src/main/java/org/olat/course/groupsandrights/BGRightsResourceType.java new file mode 100644 index 0000000000000000000000000000000000000000..e8f10b25e21e36f34cfef29cb506f17e6464d49e --- /dev/null +++ b/src/main/java/org/olat/course/groupsandrights/BGRightsResourceType.java @@ -0,0 +1,31 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.course.groupsandrights; + +/** + * + * Initial date: 23 janv. 2018<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public enum BGRightsResourceType { + repositoryEntry, + businessGroup +} diff --git a/src/main/java/org/olat/course/groupsandrights/BGRightsRow.java b/src/main/java/org/olat/course/groupsandrights/BGRightsRow.java new file mode 100644 index 0000000000000000000000000000000000000000..39d8610043664f93065351dba10042a5c62541d7 --- /dev/null +++ b/src/main/java/org/olat/course/groupsandrights/BGRightsRow.java @@ -0,0 +1,104 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.course.groupsandrights; + +import java.util.ArrayList; +import java.util.List; + +import org.olat.basesecurity.Group; +import org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement; +import org.olat.group.right.BGRightsRole; + +/** + * + * Initial date: 23 janv. 2018<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public class BGRightsRow { + private final String name; + private final Group baseGroup; + private final BGRightsRole role; + private final BGRightsResourceType resourceType; + + private List<BGRight> rightsEl; + + public BGRightsRow(Group baseGroup, String name, BGRightsRole role, BGRightsResourceType resourceType) { + this.name = name; + this.role = role; + this.baseGroup = baseGroup; + this.resourceType = resourceType; + } + + public String getName() { + return name; + } + + public Group getBaseGroup() { + return baseGroup; + } + + public BGRightsRole getRole() { + return role; + } + + public BGRightsResourceType getResourceType() { + return resourceType; + } + + public List<String> getSelectedPermissions() { + List<String> permissions = new ArrayList<String>(rightsEl.size()); + for(BGRight rightEl:rightsEl) { + if(rightEl.getSelection().isAtLeastSelected(1)) { + permissions.add(rightEl.getPermission()); + } + } + return permissions; + } + + public List<BGRight> getRightsEl() { + return rightsEl; + } + + public void setRightsEl(List<BGRight> rightsEl) { + this.rightsEl = rightsEl; + } + + public static class BGRight { + private final String permission; + private MultipleSelectionElement selection; + + public BGRight(String permission) { + this.permission = permission; + } + + public MultipleSelectionElement getSelection() { + return selection; + } + + public void setSelection(MultipleSelectionElement selection) { + this.selection = selection; + } + + public String getPermission() { + return permission; + } + } +} diff --git a/src/main/java/org/olat/course/groupsandrights/GroupsAndRightsController.java b/src/main/java/org/olat/course/groupsandrights/GroupsAndRightsController.java index b2772b08d5b165c09cac9e357e0814a1275de143..e6885e8c04b4b012b7ae572f266b86b9e82c5382 100644 --- a/src/main/java/org/olat/course/groupsandrights/GroupsAndRightsController.java +++ b/src/main/java/org/olat/course/groupsandrights/GroupsAndRightsController.java @@ -36,13 +36,12 @@ import org.olat.core.gui.components.form.flexible.impl.FormBasicController; import org.olat.core.gui.components.form.flexible.impl.FormEvent; import org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer; import org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel; -import org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiTableDataModel; import org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel; -import org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableDataModel; import org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableDataModelFactory; import org.olat.core.gui.components.link.Link; import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.WindowControl; +import org.olat.course.groupsandrights.BGRightsRow.BGRight; import org.olat.group.BusinessGroup; import org.olat.group.BusinessGroupService; import org.olat.group.right.BGRightManager; @@ -90,13 +89,13 @@ public class GroupsAndRightsController extends FormBasicController { FlexiTableColumnModel tableColumnModel = FlexiTableDataModelFactory.createFlexiTableColumnModel(); int colIndex = 0; - tableColumnModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.header.groups", colIndex++)); + tableColumnModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.header.groups", colIndex++, new BGRightsResourceNameRenderer())); tableColumnModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.header.role", colIndex++)); for(String right : CourseRights.getAvailableRights()) { tableColumnModel.addFlexiColumnModel(new DefaultFlexiColumnModel(right, colIndex++)); } - tableDataModel = new GroupsAndRightsDataModel(tableColumnModel); + tableDataModel = new GroupsAndRightsDataModel(tableColumnModel, getTranslator()); tableEl = uifactory.addTableElement(getWindowControl(), "rightList", tableDataModel, getTranslator(), formLayout); FormLayoutContainer buttonsLayout = FormLayoutContainer.createButtonLayout("buttons", getTranslator()); @@ -124,30 +123,30 @@ public class GroupsAndRightsController extends FormBasicController { } } - List<BGRightsOption> options = new ArrayList<>(); + List<BGRightsRow> options = new ArrayList<>(); String courseName = courseEntry.getDisplayname(); Group defGroup = repositoryService.getDefaultGroup(courseEntry); - options.add(getRightsOption(defGroup, courseName, tutorToRightsMap.get(defGroup), BGRightsRole.tutor)); - options.add(getRightsOption(defGroup, courseName, participantToRightsMap.get(defGroup), BGRightsRole.participant)); + options.add(getRightsOption(defGroup, courseName, tutorToRightsMap.get(defGroup), BGRightsRole.tutor, BGRightsResourceType.repositoryEntry)); + options.add(getRightsOption(defGroup, courseName, participantToRightsMap.get(defGroup), BGRightsRole.participant, BGRightsResourceType.repositoryEntry)); for(BusinessGroup group:groups) { String name = group.getName(); Group bGroup = group.getBaseGroup(); - options.add(getRightsOption(bGroup, name, tutorToRightsMap.get(bGroup), BGRightsRole.tutor)); - options.add(getRightsOption(bGroup, name, participantToRightsMap.get(bGroup), BGRightsRole.participant)); + options.add(getRightsOption(bGroup, name, tutorToRightsMap.get(bGroup), BGRightsRole.tutor, BGRightsResourceType.businessGroup)); + options.add(getRightsOption(bGroup, name, participantToRightsMap.get(bGroup), BGRightsRole.participant, BGRightsResourceType.businessGroup)); } tableDataModel.setObjects(options); } - private BGRightsOption getRightsOption(Group group, String name, BGRights r, BGRightsRole role) { - BGRightsOption options = new BGRightsOption(group, name, role); + private BGRightsRow getRightsOption(Group group, String name, BGRights r, BGRightsRole role, BGRightsResourceType type) { + BGRightsRow options = new BGRightsRow(group, name, role, type); fillCheckbox(options, r == null ? null : r.getRights()); FormLink rmLink = uifactory.addFormLink("remove_" + (++counter), "table.header.remove", "table.header.remove", flc, Link.LINK); rmLink.setUserObject(options); return options; } - private void fillCheckbox(BGRightsOption groupRights, List<String> permissions) { + private void fillCheckbox(BGRightsRow groupRights, List<String> permissions) { List<BGRight> selections = new ArrayList<>(); for(String permission : CourseRights.getAvailableRights()) { BGRight permissionEl = new BGRight(permission); @@ -162,7 +161,7 @@ public class GroupsAndRightsController extends FormBasicController { private MultipleSelectionElement createSelection(boolean selected) { String name = "cb_" + (++counter); - MultipleSelectionElement selection = uifactory.addCheckboxesHorizontal(name, flc, keys, values); + MultipleSelectionElement selection = uifactory.addCheckboxesHorizontal(name, null, flc, keys, values); selection.setEnabled(!readOnly); flc.add(name, selection); if(selected) { @@ -192,7 +191,7 @@ public class GroupsAndRightsController extends FormBasicController { private void doSaveChanges() { //collect group - List<BGRightsOption> options = tableDataModel.getObjects(); + List<BGRightsRow> options = tableDataModel.getObjects(); List<Group> groups = getAllBaseGroups(); //collect current rights @@ -207,7 +206,7 @@ public class GroupsAndRightsController extends FormBasicController { } } - for(BGRightsOption option:options) { + for(BGRightsRow option:options) { List<String> newPermissions = option.getSelectedPermissions(); BGRights rights = null; @@ -259,100 +258,4 @@ public class GroupsAndRightsController extends FormBasicController { loadModel(); tableEl.reset(false, false, true); } - - private class GroupsAndRightsDataModel extends DefaultFlexiTableDataModel<BGRightsOption> implements FlexiTableDataModel<BGRightsOption> { - - public GroupsAndRightsDataModel(FlexiTableColumnModel columnModel) { - super(columnModel); - } - - @Override - public Object getValueAt(int row, int col) { - BGRightsOption groupRights = getObject(row); - if(col == 0) { - return groupRights.getName(); - } else if (col == 1) { - BGRightsRole role = groupRights.getRole(); - switch(role) { - case tutor: return translate("tutor"); - case participant: return translate("participant"); - } - return ""; - } - - //rights - int rightPos = col - 2; - return groupRights.getRightsEl().get(rightPos).getSelection(); - } - - @Override - public GroupsAndRightsDataModel createCopyWithEmptyList() { - return new GroupsAndRightsDataModel(getTableColumnModel()); - } - } - - private static class BGRight { - private final String permission; - private MultipleSelectionElement selection; - - public BGRight(String permission) { - this.permission = permission; - } - - public MultipleSelectionElement getSelection() { - return selection; - } - - public void setSelection(MultipleSelectionElement selection) { - this.selection = selection; - } - - public String getPermission() { - return permission; - } - } - - private static class BGRightsOption { - private final String name; - private final Group baseGroup; - private final BGRightsRole role; - - private List<BGRight> rightsEl; - - public BGRightsOption(Group baseGroup, String name, BGRightsRole role) { - this.name = name; - this.role = role; - this.baseGroup = baseGroup; - } - - public String getName() { - return name; - } - - public Group getBaseGroup() { - return baseGroup; - } - - public BGRightsRole getRole() { - return role; - } - - public List<String> getSelectedPermissions() { - List<String> permissions = new ArrayList<String>(rightsEl.size()); - for(BGRight rightEl:rightsEl) { - if(rightEl.getSelection().isAtLeastSelected(1)) { - permissions.add(rightEl.getPermission()); - } - } - return permissions; - } - - public List<BGRight> getRightsEl() { - return rightsEl; - } - - public void setRightsEl(List<BGRight> rightsEl) { - this.rightsEl = rightsEl; - } - } } diff --git a/src/main/java/org/olat/course/groupsandrights/GroupsAndRightsDataModel.java b/src/main/java/org/olat/course/groupsandrights/GroupsAndRightsDataModel.java new file mode 100644 index 0000000000000000000000000000000000000000..ff293a1b21347244e7632d9e910e77370cd39f45 --- /dev/null +++ b/src/main/java/org/olat/course/groupsandrights/GroupsAndRightsDataModel.java @@ -0,0 +1,68 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.course.groupsandrights; + +import org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiTableDataModel; +import org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel; +import org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableDataModel; +import org.olat.core.gui.translator.Translator; +import org.olat.group.right.BGRightsRole; + +/** + * + * Initial date: 23 janv. 2018<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ + public class GroupsAndRightsDataModel extends DefaultFlexiTableDataModel<BGRightsRow> implements FlexiTableDataModel<BGRightsRow> { + + private final Translator translator; + + public GroupsAndRightsDataModel(FlexiTableColumnModel columnModel, Translator translator) { + super(columnModel); + this.translator = translator; + } + + @Override + public Object getValueAt(int row, int col) { + BGRightsRow rightsRow = getObject(row); + if(col == 0) { + return rightsRow; + } else if (col == 1) { + BGRightsRole role = rightsRow.getRole(); + switch(role) { + case tutor: return rightsRow.getResourceType() == BGRightsResourceType.businessGroup + ? translator.translate("tutor") : translator.translate("repo.tutor"); + case participant: return rightsRow.getResourceType() == BGRightsResourceType.businessGroup + ? translator.translate("participant") : translator.translate("repo.participant"); + } + return ""; + } + + //rights + int rightPos = col - 2; + return rightsRow.getRightsEl().get(rightPos).getSelection(); + } + + @Override + public GroupsAndRightsDataModel createCopyWithEmptyList() { + return new GroupsAndRightsDataModel(getTableColumnModel(), translator); + } +} diff --git a/src/main/java/org/olat/course/groupsandrights/_i18n/LocalStrings_de.properties b/src/main/java/org/olat/course/groupsandrights/_i18n/LocalStrings_de.properties index 1aa094651cf6ad03e65b660aa77998b78c41919a..4659e760b64ca776eff0073d50f78427504b1736 100644 --- a/src/main/java/org/olat/course/groupsandrights/_i18n/LocalStrings_de.properties +++ b/src/main/java/org/olat/course/groupsandrights/_i18n/LocalStrings_de.properties @@ -17,6 +17,8 @@ remove.all=Alle Rechte Entfernen add.all=Alle Rechte hinzuf\u00fcgen tutor=Betreuer participant=Teilnehmer +repo.tutor=Kursbetreuer +repo.participant=Kursteilnehmer diff --git a/src/main/java/org/olat/course/groupsandrights/_i18n/LocalStrings_en.properties b/src/main/java/org/olat/course/groupsandrights/_i18n/LocalStrings_en.properties index 8a6dce420cbf7d5641367060b0904d96763a288e..18600a5756c30f0d91d60d82df12ff2bee61eb42 100644 --- a/src/main/java/org/olat/course/groupsandrights/_i18n/LocalStrings_en.properties +++ b/src/main/java/org/olat/course/groupsandrights/_i18n/LocalStrings_en.properties @@ -17,6 +17,8 @@ table.header.groups=Groups table.header.remove=Remove table.header.role=Role tutor=Coach +repo.tutor=Course coach +repo.participant=Course participant