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

Synchronised Event layout select fix #2877

Merged
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
48 changes: 33 additions & 15 deletions ui/src/core/xibo-calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,8 @@ $(function() {
}
});

// Function to update the Condition dropdown according to the selected metric's available condition
// Function to update the Condition dropdown
// according to the selected metric's available condition
function updateConditionField($row, conditions, selectedCondition) {
const $conditionField = $row.find('select[name="criteria_condition[]"]');

Expand All @@ -942,17 +943,22 @@ function updateConditionField($row, conditions, selectedCondition) {
// Populate with provided conditions
conditions.forEach((condition) => {
$conditionField.append(
$('<option>', { value: condition.id }).text(condition.name)
$('<option>', {value: condition.id}).text(condition.name),
);
});

// Pre-select the condition if provided, otherwise select the first condition
// Pre-select the condition if provided
// otherwise select the first condition
$conditionField.val(selectedCondition || conditions[0]?.id || '');
}
}

// Function to revert the Condition dropdown to its default selection
function updateConditionFieldToDefault($row, defaultConditions, selectedCondition) {
function updateConditionFieldToDefault(
$row,
defaultConditions,
selectedCondition,
) {
const $conditionField = $row.find('select[name="criteria_condition[]"]');

if ($conditionField.length > 0 && defaultConditions) {
Expand All @@ -962,11 +968,12 @@ function updateConditionFieldToDefault($row, defaultConditions, selectedConditio
// Populate with default conditions
defaultConditions.forEach((condition) => {
$conditionField.append(
$('<option>', { value: condition.id }).text(condition.name)
$('<option>', {value: condition.id}).text(condition.name),
);
});

// Pre-select the condition if provided, otherwise select the first condition
// Pre-select the condition if provided
// otherwise select the first condition
$conditionField.val(selectedCondition || defaultConditions[0]?.id || '');
}
}
Expand Down Expand Up @@ -2226,7 +2233,13 @@ const setupSelectForSchedule = function(dialog) {

dialog.find('#contentSelectorTable tbody')
.html('').append(
templates.calendar.syncEventContentSelector(response.data),
templates.calendar.syncEventContentSelector({
...response.data,
...{
urlForLayoutSearch: urlForLayoutSearch,
trans: translations.schedule.syncEventSelector,
},
}),
);
const formId = dialog.find('form').attr('id');
dialog.find('.pagedSelect select.form-control.syncContentSelect')
Expand All @@ -2251,10 +2264,10 @@ const setupSelectForSchedule = function(dialog) {

dialog
.find('.pagedSelect select.form-control.syncContentSelect')
.not('#layout_' + leadDisplayId)
.each(function() {
$(ev.currentTarget).data().initialValue = leadLayoutId;
makePagedSelect($(ev.currentTarget), '#' + formId);
.not('#layoutId_' + leadDisplayId)
.each(function(_idx, el) {
$(el).data().initialValue = leadLayoutId;
makePagedSelect($(el), '#' + formId);
});
});
}, (xhr) => {
Expand Down Expand Up @@ -2294,7 +2307,7 @@ const configureCriteriaFields = function(dialog) {
typeId,
selectedMetric,
elementValue,
selectedCondition
selectedCondition,
) {
const $metricLabel = $row.find('label[for="criteria_metric[]"]');
let $metricSelect;
Expand Down Expand Up @@ -2343,8 +2356,13 @@ const configureCriteriaFields = function(dialog) {
updateConditionField($row, metric.conditions, selectedCondition);
} else {
// Use default conditions if none are defined
const criteriaDefaultCondition = $('#scheduleCriteriaFields').data('criteriaDefaultCondition');
updateConditionFieldToDefault($row, criteriaDefaultCondition, selectedCondition);
const criteriaDefaultCondition =
$('#scheduleCriteriaFields').data('criteriaDefaultCondition');
updateConditionFieldToDefault(
$row,
criteriaDefaultCondition,
selectedCondition,
);
}
}
}
Expand Down Expand Up @@ -2413,7 +2431,7 @@ const configureCriteriaFields = function(dialog) {
element.type,
element.metric,
element.value,
element.condition
element.condition,
);
});
} else {
Expand Down
6 changes: 3 additions & 3 deletions ui/src/templates/calendar/sync-event-content-selector.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
<td>{{display}}</td>
<td>
<div class="form-group pagedSelect">
<select class="form-control syncContentSelect single-select" name="layoutId_{{displayId}}" id="layoutId_{{displayId}}" data-search-url="{{urlForLayoutSearch}}"
<select class="form-control syncContentSelect single-select" name="layoutId_{{displayId}}" id="layoutId_{{displayId}}" data-search-url="{{../urlForLayoutSearch}}"
data-search-term="layout" data-width="100%" data-id-property="layoutId" data-text-property="layout" data-anchor-element="#contentSelectorTable"
data-initial-key="layoutId" data-initial-value="{{layoutId}}" data-display-id="{{displayId}}" data-lead-display-id="{{leadDisplayId}}">
<option></option>
</select>
</div>
{{#eq displayId leadDisplayId}}
<button data-display-id="{{displayId}}" id="setMirrorContent" type="button" class="btn btn-success d-none"
title="{{trans.setOnAllDisplays}}">
{{trans.mirror}}
title="{{../trans.setOnAllDisplays}}">
{{../trans.mirror}}
</button>
{{/eq}}
<input name="displayGroupIds[]" type="hidden" id="displayGroupIds[]" value="{{displayGroupId}}">
Expand Down