Skip to content

Commit

Permalink
Layout Editor: Sharing is broken (#2288)
Browse files Browse the repository at this point in the history
  • Loading branch information
maurofmferrao committed Jan 5, 2024
1 parent 8c079b3 commit e9476a7
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 21 deletions.
6 changes: 6 additions & 0 deletions ui/src/editor-core/widget.js
Expand Up @@ -667,6 +667,12 @@ Widget.prototype.saveElements = function(
forceRequest = false,
} = {},
) {
// If widget isn't editable, throw an error
if (this.isEditable === false) {
toastr.error(errorMessagesTrans.canvasWidgetNotShared);
return;
}

const self = this;
const app = this.editorObject;
const widgetId = this.widgetId;
Expand Down
57 changes: 54 additions & 3 deletions ui/src/layout-editor/main.js
Expand Up @@ -1144,6 +1144,11 @@ lD.undoLastAction = function() {
* Delete selected object
*/
lD.deleteSelectedObject = function() {
// Prevent delete if it doesn't have permissions
if (lD.selectedObject.isDeletable === false) {
return;
}

// For now, we always delete the region
if (lD.selectedObject.type === 'region') {
lD.deleteObject(
Expand Down Expand Up @@ -2918,6 +2923,18 @@ lD.openContextMenu = function(obj, position = {x: 0, y: 0}) {
layoutObject.type === 'element-group'
);

// If target is a frame, send single widget info
const singleWidget = (
layoutObject.type === 'region' &&
layoutObject.subType === 'frame'
) ? Object.values(layoutObject.widgets)[0] : {};

// If target is group or element group, send parent widget
const elementWidget = (
layoutObject.type === 'element' ||
layoutObject.type === 'element-group'
) ? lD.getObjectByTypeAndId('widget', objAuxId, 'canvas') : {};

// Create menu and append to the designer div
// ( using the object extended with translations )
lD.editorContainer.append(
Expand All @@ -2927,6 +2944,12 @@ lD.openContextMenu = function(obj, position = {x: 0, y: 0}) {
canHaveNewConfig: canHaveNewConfig,
canChangeLayer: canChangeLayer,
canUngroup: canUngroup,
widget: singleWidget,
isElementBased: (
layoutObject.type === 'element' ||
layoutObject.type === 'element-group'
),
elementWidget: elementWidget,
})),
);

Expand Down Expand Up @@ -3301,9 +3324,37 @@ lD.openContextMenu = function(obj, position = {x: 0, y: 0}) {
});
});
} else {
layoutObject.editPropertyForm(
target.data('property'), target.data('propertyType'),
);
const property = target.data('property');
const propertyType = target.data('propertyType');

// If we're editing permissions and it's a frame
// edit the widget's permissions instead
if (
property === 'PermissionsWidget' &&
layoutObject.type === 'region' &&
layoutObject.subType === 'frame'
) {
// Call edit for widget instead
const regionWidget = Object.values(layoutObject.widgets)[0];
regionWidget.editPropertyForm('Permissions');
} else if (
property === 'PermissionsCanvasWidget' &&
(
layoutObject.type === 'element' ||
layoutObject.type === 'element-group'
)
) {
// Call edit for canvas widget instead
const canvasWidget =
lD.getObjectByTypeAndId('widget', objAuxId, 'canvas');
canvasWidget.editPropertyForm('Permissions');
} else {
// Call normal edit form
layoutObject.editPropertyForm(
property,
propertyType,
);
}
}

// Remove context menu
Expand Down
1 change: 1 addition & 0 deletions ui/src/layout-editor/region.js
Expand Up @@ -33,6 +33,7 @@ const Region = function(id, data, {backgroundColor = '#aaa'} = {}) {
this.isDeletable = data.isDeletable;
this.isPermissionsModifiable = data.isPermissionsModifiable;
this.isPlaylist = data.type === 'playlist';
this.isFrame = data.type === 'frame';
this.isFrameOrZone = (
data.type === 'frame' ||
data.type === 'zone'
Expand Down
13 changes: 9 additions & 4 deletions ui/src/layout-editor/viewer.js
Expand Up @@ -824,7 +824,8 @@ Viewer.prototype.handleInteractions = function() {
clicks = 0;

if (
$(e.target).data('subType') === 'playlist'
$(e.target).data('subType') === 'playlist' &&
$(e.target).hasClass('editable')
) {
// Edit region if it's a playlist
playlistEditorBtnClick($(e.target).attr('id'));
Expand Down Expand Up @@ -1166,8 +1167,11 @@ Viewer.prototype.renderRegion = function(
// Append layout html to the container div
$container.html(html);

// If it's playlist add some playlist controls
if (isPlaylist) {
// If it's (an editable) playlist, add some playlist controls
if (
isPlaylist &&
region.isEditable
) {
region.playlistCountOfWidgets = res.extra && res.extra.countOfWidgets ?
res.extra.countOfWidgets : 1;

Expand Down Expand Up @@ -2799,7 +2803,8 @@ Viewer.prototype.updateMoveable = function(
(
$selectedElement &&
$.contains(document, $selectedElement[0]) &&
!$selectedElement.hasClass('drawerWidget')
!$selectedElement.hasClass('drawerWidget') &&
$selectedElement.hasClass('editable')
)
) {
if ($selectedElement.hasClass('designer-element-group')) {
Expand Down
8 changes: 2 additions & 6 deletions ui/src/style/layout-editor.scss
Expand Up @@ -736,11 +736,8 @@ body.editor-opened {
color: $xibo-color-primary-l5;
padding: 30px;
background-color: $xibo-color-semantic-error;

&.invalid-region-message {
margin: 16px;
border-radius: 3px;
}
border-radius: 4px;
margin: 16px 16px 0 0;
}

.loading-container {
Expand Down Expand Up @@ -1489,7 +1486,6 @@ body.editor-opened {

/* Locked mode */
#layout-editor #lockedOverlay {
z-index: 1;
display: block;
position: absolute;
}
Expand Down
28 changes: 24 additions & 4 deletions ui/src/templates/context-menu.hbs
Expand Up @@ -67,10 +67,30 @@
</div>
{{/if}}

{{#if isPermissionsModifiable}}
<div class="context-menu-btn permissionsBtn" data-title="{{trans.editPermissions}}" data-property="Permissions" data-toggle="tooltip" data-container=".context-menu" data-placement="bottom">
<i class="tool-icon-permissions"></i><span>{{trans.editPermissions}}</span>
</div>
{{#if isFrame}}
{{#if widget.isPermissionsModifiable}}
<div class="context-menu-btn permissionsBtn" data-title="{{trans.editPermissions}}" data-property="PermissionsWidget" data-toggle="tooltip" data-container=".context-menu" data-placement="bottom">
<i class="tool-icon-permissions"></i><span>{{trans.editPermissions}}</span>
</div>
{{/if}}

{{#if isPermissionsModifiable}}
<div class="context-menu-btn permissionsBtn" data-title="{{trans.editRegionPermissions}}" data-property="Permissions" data-toggle="tooltip" data-container=".context-menu" data-placement="bottom">
<i class="tool-icon-permissions"></i><span>{{trans.editRegionPermissions}}</span>
</div>
{{/if}}
{{else if isElementBased}}
{{#if elementWidget.isPermissionsModifiable}}
<div class="context-menu-btn permissionsBtn" data-title="{{trans.editPermissions}}" data-property="PermissionsCanvasWidget" data-toggle="tooltip" data-container=".context-menu" data-placement="bottom">
<i class="tool-icon-permissions"></i><span>{{trans.editPermissions}}</span>
</div>
{{/if}}
{{else}}
{{#if isPermissionsModifiable}}
<div class="context-menu-btn permissionsBtn" data-title="{{trans.editPermissions}}" data-property="Permissions" data-toggle="tooltip" data-container=".context-menu" data-placement="bottom">
<i class="tool-icon-permissions"></i><span>{{trans.editPermissions}}</span>
</div>
{{/if}}
{{/if}}

{{#if canBeCopied}}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/templates/viewer-element-group.hbs
@@ -1,4 +1,4 @@
<div id="{{element.groupId}}" class="designer-element-group editable viewer-object-select"
<div id="{{element.groupId}}" class="designer-element-group {{#if element.isEditable}}editable{{/if}} viewer-object-select"
data-type="element-group"
data-region-id="{{element.regionId}}"
data-widget-id="{{element.widgetId}}"
Expand Down
2 changes: 1 addition & 1 deletion ui/src/templates/viewer-element.hbs
@@ -1,5 +1,5 @@
<div id="{{element.elementId}}"
class="designer-element viewer-object-select {{#if element.selected}}selected{{/if}} deletable"
class="designer-element viewer-object-select {{#if element.selected}}selected{{/if}} {{#if element.isEditable}}editable{{/if}} {{#if element.isDeletable}}deletable{{/if}} "
data-type="element"
data-element-type="{{#if element.elementType}}{{element.elementType}}{{else}}global{{/if}}"
data-sub-type="{{element.id}}"
Expand Down
3 changes: 3 additions & 0 deletions views/common.twig
Expand Up @@ -457,6 +457,7 @@
editTransIn: "{{ "Edit Transition In"|trans }}",
editTransOut: "{{ "Edit Transition Out" |trans }}",
editPermissions: "{{ "Edit Sharing" |trans }}",
editRegionPermissions: "{{ "Edit Region Sharing" |trans }}",
editPlaylist: "{{ "Edit Playlist" |trans }}",
options: "{% trans "Options" %}",
moveLeft: "{{ "Move one step left" |trans }}",
Expand Down Expand Up @@ -511,6 +512,7 @@
bottomRight: "{{ "Bottom/Right" |trans }}",
},
somethingWentWrong: "{{ "Something went wrong!"|trans }}",
somethingWentWrongEditPermissions: "{{ "Selected item is not shared with you with edit permission!"|trans }}",
actions: {
noActionsToShow: "{{ "No actions to show"|trans }}",
otherActions: "{{ "Other Actions" |trans }}",
Expand Down Expand Up @@ -837,6 +839,7 @@
unknown: "{{ "Unknown Error"|trans }}",
invalidRegion: "{{ "Region is invalid: Please delete it to validate the Layout!"|trans }}",
failedToImportMedia: "{{ "Failed to import media!"|trans }}",
canvasWidgetNotShared: "{{ "This Canvas is not shared with you with edit permission!"|trans }}",
};
var widgetStatusTrans = {
Expand Down
5 changes: 3 additions & 2 deletions views/user-form-permissions.twig
Expand Up @@ -36,7 +36,9 @@
{% elseif (object.type == "playlist") or (object.type == "subplaylist") %}
{% set objectName = "Playlist"|trans %}
{% elseif object.type == "frame" %}
{% set objectName = "Widget"|trans %}
{% set objectName = "Region"|trans %}
{% elseif object.type == "global" %}
{% set objectName = "Canvas"|trans %}
{% else %}
{% set objectName = entity|trans %}
{% endif %}
Expand All @@ -55,7 +57,6 @@
<div class="permissions-form" id="permissionsForm">
<div class="row">
<div class="col-md-12">
<p>{{object.type}}</p>
<div class="XiboGrid permissionsGrid" id="{{ randomId }}"
data-url="{{ url_for("user.permissions", {entity: entity, id: objectId}) }}"
data-permissions="{{ permissions|json_encode }}">
Expand Down

0 comments on commit e9476a7

Please sign in to comment.