Skip to content
Merged

Dump #670

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
5 changes: 3 additions & 2 deletions app/assets/javascripts/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ export const mustache_i18n = function() {
export const applyStopPopupManagePlanning = function(view, managePlanning) {
var mp = managePlanning || {};
view.manage_organize = mp.manage_organize !== false;
view.planning_move_stops_visible = Boolean(mp.manage_route_stops);
view.planning_move_stops_usable = Boolean(mp.manage_route_stops) && !Boolean(mp.disable_route_stops);
view.send_stop_to_route_visible = Boolean(mp.manage_stop_move);
view.send_stop_to_route_usable = Boolean(mp.manage_stop_move) && !Boolean(mp.disable_stop_move);
view.planning_move_stops_visible = Boolean(mp.manage_route_stops) && view.send_stop_to_route_visible;
view.planning_move_stops_usable =
Boolean(mp.manage_route_stops) && !Boolean(mp.disable_route_stops) && view.send_stop_to_route_usable;
view.move_stop_allowed = view.send_stop_to_route_usable;
view.stop_active_allowed = Boolean(mp.manage_stop_active) && !Boolean(mp.disable_stop_active);
};
Expand Down
16 changes: 16 additions & 0 deletions app/assets/javascripts/modals/move_stops_modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class MoveStopsModal {
this.mustacheI18n = null;
this.modalSelector = '#planning-move-stops-modal';
this.isInitialized = false;
this.planningMoveStopsUsable = true;
}

/**
Expand All @@ -59,6 +60,7 @@ export class MoveStopsModal {
this.refreshSidebarRoute = options.refreshSidebarRoute;
this.updatePlanningDataHeader = options.updatePlanningDataHeader || function() {};
this.mustacheI18n = options.mustacheI18n;
this.planningMoveStopsUsable = options.planningMoveStopsUsable !== false;

if (!this.isInitialized) {
this.setupEventHandlers();
Expand All @@ -73,6 +75,10 @@ export class MoveStopsModal {
// Load modal content when opened via data-toggle="modal"
$(this.modalSelector).off('show.bs.modal.moveStops').on('show.bs.modal.moveStops', (ev) => {
try {
if (!this.planningMoveStopsUsable) {
ev.preventDefault();
return;
}
const trigger = ev.relatedTarget;
const routeId = trigger && trigger.getAttribute && trigger.getAttribute('data-route-id');
if (!routeId) return;
Expand All @@ -99,12 +105,16 @@ export class MoveStopsModal {

// Move stops button click
$("#move-stops-modal").off('click').on('click', () => {
if (!this.planningMoveStopsUsable) {
return;
}
this.handleMoveStops();
});

// Listen when server injected content is ready, then initialize behaviors
$(document).off('move-stops:content-updated').on('move-stops:content-updated', () => {
try {
$('#move-stops-modal').prop('disabled', !this.planningMoveStopsUsable);
// Initialize UI widgets
$('#move-stops-toggle').toggleSelect();
$('[type="checkbox"][data-toggle="disable-multiple-actions"]').toggleMultipleActions();
Expand Down Expand Up @@ -385,6 +395,9 @@ export class MoveStopsModal {
* @param {string} routeId - Route ID to show modal for
*/
showModal(routeId) {
if (!this.planningMoveStopsUsable) {
return;
}
// Show loading spinner immediately
$(`${this.modalSelector} .modal-body`).html('<div class="spinner"><i class="fa fa-spin fa-2x fa-spinner"></i></div>').unbind();
$(this.modalSelector).modal('show');
Expand All @@ -403,6 +416,9 @@ export class MoveStopsModal {
* @param {Array<number>} stopIds
*/
showModalForStops(stopIds) {
if (!this.planningMoveStopsUsable) {
return;
}
// Show loading spinner immediately
$(`${this.modalSelector} .modal-body`).html('<div class="spinner"><i class="fa fa-spin fa-2x fa-spinner"></i></div>').unbind();
$(this.modalSelector).modal('show');
Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/plannings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2854,7 +2854,7 @@ export const plannings_edit = function(params) {
return;
}
var mpToolbar = params.manage_planning;
var planningMoveStopsUsable = mpToolbar && mpToolbar.manage_route_stops && !mpToolbar.disable_route_stops;
var planningMoveStopsUsable = mpToolbar && mpToolbar.planning_move_stops_usable;
var stopSortableDisabled = !planningMoveStopsUsable;
$sortable_route.sortable({
distance: 8,
Expand Down Expand Up @@ -2945,6 +2945,7 @@ export const plannings_edit = function(params) {
quantities: params.quantities,
routesLayer: routesLayer,
refreshSidebarRoute: refreshSidebarRoute,
planningMoveStopsUsable: !!(params.manage_planning && params.manage_planning.planning_move_stops_usable),
updatePlanningDataHeader: function() {
updateDataHeader(planning_id);
},
Expand Down
61 changes: 53 additions & 8 deletions app/assets/javascripts/utils/lasso.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

'use strict';

import { ajaxError, beforeSendWaiting, completeAjaxMap } from '../ajax.js';
import { ajaxError } from '../ajax.js';
import { moveStopsModal } from '../modals/move_stops_modal.js';

/**
Expand All @@ -36,6 +36,7 @@ export class LassoModule {
this.dataExtractor = null;
this.waitingRoute = null;
this.refreshRoute = null;
this.managePlanning = {};
}

/**
Expand All @@ -59,6 +60,7 @@ export class LassoModule {
this.map = mapInstance;
this.planningId = planningIdParam;
this.routesLayer = routesLayerInstance;
this.managePlanning = (routesLayerInstance && routesLayerInstance.options && routesLayerInstance.options.popupOptions) || {};

// Store the functions passed from plannings.js
this.waitingRoute = routeWaitingFunc;
Expand All @@ -83,11 +85,7 @@ export class LassoModule {
});

this.map.on('lasso.finished', (event) => {
if (typeof LassoSelection === 'function') {
LassoSelection(event, this.map, document.querySelector('.sidebar'));
} else {
this.onLassoFinished(event);
}
this.onLassoFinished(event);
});

return this.addLassoControl();
Expand Down Expand Up @@ -235,8 +233,7 @@ export class LassoModule {
}
});

// Use MoveStops modal instead of custom modal
this.showMoveStopsModalForLassoSelection();
this.showLassoSelectionModal(processedLayers);
} else {
// Reset lasso tool when selection is empty
this.disableLasso();
Expand Down Expand Up @@ -279,11 +276,58 @@ export class LassoModule {
return processedLayers;
}

showLassoSelectionModal(processedLayers) {
const mp = this.managePlanning || {};
if (!mp.planning_move_stops_visible) {
this.clearLassoSelection();
this.disableLasso();
return;
}

const stopIds = processedLayers
.map((layer) => layer && layer.properties && layer.properties.stop_id)
.filter(Boolean);
if (!stopIds.length) {
return;
}

const self = this;
$.ajax({
url: `/plannings/${this.planningId}/selection_details`,
data: { stop_ids: stopIds.join(',') },
method: 'GET',
success(html) {
$('#lasso-info-modal').remove();
$('body').append(html);
$('#lasso-info-modal').modal('show');

$('#move-stops-btn').off('click.lassoMove').on('click.lassoMove', () => {
if (!mp.planning_move_stops_usable || !moveStopsModal.planningMoveStopsUsable) {
return;
}
$('#lasso-info-modal').modal('hide');
self.showMoveStopsModalForLassoSelection();
});

$('#lasso-info-modal').off('hidden.bs.modal.lasso').on('hidden.bs.modal.lasso', function() {
self.clearLassoSelection();
self.disableLasso();
$(this).remove();
});
},
error: ajaxError
});
}

/**
* Show MoveStops modal for lasso selection
* This method uses the existing MoveStops modal and simulates stop selection
*/
showMoveStopsModalForLassoSelection() {
if (!(this.managePlanning && this.managePlanning.planning_move_stops_usable)) {
return;
}

// Extract stops from selected layers (including processed clusters)
const selectedStops = [];
const processedLayers = this.processSelectedLayers(this.selectedLayers);
Expand Down Expand Up @@ -398,6 +442,7 @@ export class LassoModule {
this.dataExtractor = null;
this.waitingRoute = null;
this.refreshRoute = null;
this.managePlanning = {};
this.selectedLayers = [];
this.isLassoActive = false;
}
Expand Down
11 changes: 8 additions & 3 deletions app/controllers/concerns/planning_toolbar_planning_flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,17 @@ def apply_planning_toolbar_operation_flags!
apply_route_toolbar_operation_flags!
apply_stop_toolbar_operation_flags!

@manage_planning[:planning_move_stops_visible] = @manage_planning[:manage_route_stops]
@manage_planning[:planning_move_stops_usable] = @manage_planning[:manage_route_stops] && !@manage_planning[:disable_route_stops]

@manage_planning[:send_stop_to_route_visible] = @manage_planning[:manage_stop_move]
@manage_planning[:send_stop_to_route_usable] = @manage_planning[:manage_stop_move] && !@manage_planning[:disable_stop_move]

# Bulk move requires both route stops management and per-stop move permission
@manage_planning[:planning_move_stops_visible] =
@manage_planning[:manage_route_stops] && @manage_planning[:send_stop_to_route_visible]
@manage_planning[:planning_move_stops_usable] =
@manage_planning[:manage_route_stops] &&
!@manage_planning[:disable_route_stops] &&
@manage_planning[:send_stop_to_route_usable]

@manage_planning[:manage_activate_stops] =
planning_op_visible.call('activate_stops') && @manage_planning[:manage_stop_active]
@manage_planning[:disable_activate_stops] =
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/plannings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ def modal

# Render move stops modal content via Rails (.js.erb)
def move_stops_modal
bootstrap_manage_planning_flags!
deny_unless_operation_usable!(:route, 'stops')
deny_unless_operation_usable!(:stop, 'move_stop')

route =
if params[:route_id]
route_id = Integer(params[:route_id])
Expand Down Expand Up @@ -734,6 +738,7 @@ def move_respond
route_ids << previous_route_id if previous_route_id != route_id
else
deny_unless_operation_usable!(:route, 'stops')
deny_unless_operation_usable!(:stop, 'move_stop')
params[:stop_ids].map!(&:to_i)
stops = Stop.joins(:route)
.where(routes: { planning_id: @planning.id })
Expand Down
6 changes: 3 additions & 3 deletions app/views/customers/import.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<%= bootstrap_form_for @customer, url: upload_dump_customers_path, layout: :horizontal, html: { class: 'form-horizontal', multipart: true } do |f| %>

<div class='row'>
<label class="col-md-offset-2 col-md-8 control-label" for="uploaded-customer"><%= t('activerecord.models.customer') %></label>
<label class="col-md-offset-2 col-md-8 control-label" for="uploaded-customer"><%= t('activerecord.models.customer') %></label>
<div class='col-md-offset-2 col-md-8'>
<label class="btn btn-default form-control" id="upload-customer" for="uploaded-customer">
<%= f.file_field :uploaded_file, class: "hidden", id: 'uploaded-customer', onchange: "$('.file-label').html(this.files[0].name);$('.file-label').attr('title',this.files[0].name)" %>
<p class="file-label"><%= t('.label') %></p>
<%= f.file_field :uploaded_file, class: "hidden", id: 'uploaded-customer', onchange: "$('.file-label').html(this.files[0].name);$('.file-label').attr('title',this.files[0].name)" %>
</label>
<p class="help-block file-label"><%= t('.label') %></p>
</div>
</div>

Expand Down
5 changes: 3 additions & 2 deletions app/views/plannings/_edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@
.modal-body.routes
.clearfix
.modal-footer
%button#move-stops-modal.btn.btn-primary{type: "button"}
= t('plannings.edit.move_stops')
- if @manage_planning[:planning_move_stops_visible]
%button#move-stops-modal.btn.btn-primary{type: "button", disabled: !@manage_planning[:planning_move_stops_usable]}
= t('plannings.edit.move_stops')

#planning-send-sms-drivers-modal.modal.fade{role: "dialog", tabindex: "-1"}

Expand Down
10 changes: 6 additions & 4 deletions app/views/routes/operations/_stops.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- move_stops_visible = @manage_planning[:planning_move_stops_visible]
- move_stops_usable = @manage_planning[:planning_move_stops_usable]
- if @manage_planning[:manage_route_stops]
.btn-group
Expand Down Expand Up @@ -41,11 +42,12 @@
%a.reverse_order{href: "/plannings/#{summary[:planning_id]}/#{route[:route_id]}/reverse_order"}
%i.fa.fa-arrow-right-arrow-left.fa-rotate-90.fa-fw
= t('plannings.edit.reverse_order')
%li{class: ('disabled' unless move_stops_usable)}
- if move_stops_visible
- if move_stops_usable
%a{"data-route-id": route[:route_id], "data-target": "#planning-move-stops-modal", "data-toggle": "modal", href: "#"}
%i.fa.fa-truck-ramp-box.fa-fw
= t('plannings.edit.move_stops')
%li
%a{"data-route-id": route[:route_id], "data-target": "#planning-move-stops-modal", "data-toggle": "modal", href: "#"}
%i.fa.fa-truck-ramp-box.fa-fw
= t('plannings.edit.move_stops')
- else
%span.text-muted
%i.fa.fa-truck-ramp-box.fa-fw
Expand Down
7 changes: 4 additions & 3 deletions app/views/shared/_selection_details.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
.lasso-actions
%button#clear-lasso-selection.btn.btn-default{"data-dismiss" => "modal", type: "button"}
= t('all.verb.cancel')
%button#move-stops-btn.btn.btn-primary{disabled: true, type: "button", style: ('display: none;' unless move_stops_visible), data: { move_forbidden: (!move_stops_usable) }}
%i.fa.fa-arrow-right.fa-fw
= t('plannings.edit.lasso.move_stops')
- if move_stops_visible
%button#move-stops-btn.btn.btn-primary{disabled: !move_stops_usable, type: "button", title: (t('plannings.edit.lasso.move_stops_forbidden') unless move_stops_usable)}
%i.fa.fa-arrow-right.fa-fw
= t('plannings.edit.lasso.move_stops')
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2166,6 +2166,7 @@ en:
toggle: Enable/disable lasso selection
selection_info: Selection information
move_stops: Move stops
move_stops_forbidden: You do not have permission to move stops
stops_moved_success: Stops moved successfully
stops_moved_error: Error moving stops
select_target_route: Transfer stops
Expand Down
1 change: 1 addition & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2266,6 +2266,7 @@ fr:
toggle: Activer/désactiver la sélection par lasso
selection_info: Informations de sélection
move_stops: Déplacer les arrêts
move_stops_forbidden: Vous n’avez pas la permission de déplacer des arrêts
stops_moved_success: Arrêts déplacés avec succès
stops_moved_error: Erreur lors du déplacement des arrêts
select_target_route: Transférer les arrêts
Expand Down
Loading
Loading