From 40952600e7ba214d11e66eb408050fef98e2f7d0 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 13 Feb 2017 17:00:27 +0100 Subject: [PATCH] basic interface structure for space management --- .../controllers/main_nav.coffee.erb | 10 +++ .../javascripts/controllers/spaces.coffee | 45 +++++++++++++ app/assets/javascripts/router.coffee.erb | 20 ++++++ app/assets/javascripts/services/space.coffee | 8 +++ app/assets/templates/spaces/index.html.erb | 63 +++++++++++++++++++ config/locales/app.public.en.yml | 8 +++ config/locales/app.public.fr.yml | 8 +++ config/routes.rb | 1 + 8 files changed, 163 insertions(+) create mode 100644 app/assets/javascripts/controllers/spaces.coffee create mode 100644 app/assets/javascripts/services/space.coffee create mode 100644 app/assets/templates/spaces/index.html.erb diff --git a/app/assets/javascripts/controllers/main_nav.coffee.erb b/app/assets/javascripts/controllers/main_nav.coffee.erb index 0b83d9ce3..c0ff2415f 100644 --- a/app/assets/javascripts/controllers/main_nav.coffee.erb +++ b/app/assets/javascripts/controllers/main_nav.coffee.erb @@ -28,6 +28,11 @@ Application.Controllers.controller "MainNavController", ["$scope", "$location", linkText: 'events_registrations' linkIcon: 'tags' } + { + state: 'app.public.spaces_list' + linkText: 'reserve_a_space' + linkIcon: 'rocket' + } { state: 'app.public.calendar' linkText: 'public_calendar' @@ -86,6 +91,11 @@ Application.Controllers.controller "MainNavController", ["$scope", "$location", linkText: 'manage_the_machines' linkIcon: 'cogs' } + { + state: 'app.public.spaces_list' + linkText: 'manage_the_spaces' + linkIcon: 'rocket' + } { state: 'app.admin.project_elements' linkText: 'manage_the_projects_elements' diff --git a/app/assets/javascripts/controllers/spaces.coffee b/app/assets/javascripts/controllers/spaces.coffee new file mode 100644 index 000000000..33d3b9439 --- /dev/null +++ b/app/assets/javascripts/controllers/spaces.coffee @@ -0,0 +1,45 @@ + +## +# Manages the transition when a user clicks on the reservation button. +# According to the status of user currently logged into the system, redirect him to the reservation page, +# or display a modal window asking him to login or to create an account. +# @param space {{id:number}} An object containg the id of the space to book, +# the object will be completed before the fonction returns. +# @param e {Object} see https://docs.angularjs.org/guide/expression#-event- +## +_reserveSpace = (space, e) -> + _this = this + e.preventDefault() + e.stopPropagation() + + # if a user is authenticated ... + if _this.$scope.isAuthenticated() + _this.$state.go('app.logged.space_reserve', { id: space.id }) + # if the user is not logged, open the login modal window + else + _this.$scope.login() + + + +## +# Controller used in the public listing page, allowing everyone to see the list of spaces +## +Application.Controllers.controller "SpacesController", ["$scope", "$state", 'spacesPromise', ($scope, $state, spacesPromise) -> + + ## Retrieve the list of machines + $scope.spaces = spacesPromise + + ## + # Redirect the user to the space details page + ## + $scope.showSpace = (space) -> + $state.go('app.public.space_show', { id: space.slug }) + + ## + # Callback to book a reservation for the current machine + ## + $scope.reserveSpace = _reserveSpace.bind + $scope: $scope + $state: $state +] + diff --git a/app/assets/javascripts/router.coffee.erb b/app/assets/javascripts/router.coffee.erb index b62151748..9aacff334 100644 --- a/app/assets/javascripts/router.coffee.erb +++ b/app/assets/javascripts/router.coffee.erb @@ -388,6 +388,26 @@ angular.module('application.router', ['ui.router']). translations: [ 'Translations', (Translations) -> Translations.query(['app.admin.machines_edit', 'app.shared.machine']).$promise ] + + # spaces + .state 'app.public.spaces_list', + url: '/spaces' + views: + 'main@': + templateUrl: '<%= asset_path "spaces/index.html.erb" %>' + controller: 'SpacesController' + resolve: + spacesPromise: ['Space', (Space)-> + Space.query().$promise + ] + translations: [ 'Translations', (Translations) -> + Translations.query(['app.public.spaces_list']).$promise + ] + .state 'app.logged.space_reserve', + url: '/spaces/:id/reserve' + .state 'app.admin.space_new', + url: '/spaces/new' + # trainings .state 'app.public.trainings_list', url: '/trainings' diff --git a/app/assets/javascripts/services/space.coffee b/app/assets/javascripts/services/space.coffee new file mode 100644 index 000000000..802da06cd --- /dev/null +++ b/app/assets/javascripts/services/space.coffee @@ -0,0 +1,8 @@ +'use strict' + +Application.Services.factory 'Space', ["$resource", ($resource)-> + $resource "/api/spaces/:id", + {id: "@id"}, + update: + method: 'PUT' +] diff --git a/app/assets/templates/spaces/index.html.erb b/app/assets/templates/spaces/index.html.erb new file mode 100644 index 000000000..e640c1ec8 --- /dev/null +++ b/app/assets/templates/spaces/index.html.erb @@ -0,0 +1,63 @@ +
+
+
+
+ +
+
+
+
+

{{ 'the_spaces' }}

+
+
+ + +
+
+ + +
+ +
+ +
+ + +
+
+ +
+
+
+
+

{{space.name}}

+
+ +
+ + +
+
+ + + +
diff --git a/config/locales/app.public.en.yml b/config/locales/app.public.en.yml index 4eae93c2d..e4fa7df8b 100644 --- a/config/locales/app.public.en.yml +++ b/config/locales/app.public.en.yml @@ -31,6 +31,7 @@ en: reserve_a_machine: "Reserve a Machine" trainings_registrations: "Trainings registrations" events_registrations: "Events registrations" + reserve_a_space: "Reserve a Space" projects_gallery: "Projects gallery" subscriptions: "Subscriptions" public_calendar: "Calendar" @@ -44,6 +45,7 @@ en: subscriptions_and_prices: "Subscriptions and Prices" manage_the_events: "Manage the events" manage_the_machines: "Manage the Machines" + manage_the_spaces: "Manage the Spaces" manage_the_projects_elements: "Manage the Projects Elements" statistics: "Statistics" customization: "Customization" @@ -246,6 +248,12 @@ en: you_can_shift_this_reservation_on_the_following_slots: "You can shift this reservation on the following slots:" calendar: + # public calendar calendar: "Calendar" show_no_disponible: "Show the slots no disponibles" filter-calendar: "Filter calendar" + + spaces_list: + # list of spaces + the_spaces: "The spaces" + add_a_space: "Add a space" \ No newline at end of file diff --git a/config/locales/app.public.fr.yml b/config/locales/app.public.fr.yml index a6e7be6c8..41236ae2a 100644 --- a/config/locales/app.public.fr.yml +++ b/config/locales/app.public.fr.yml @@ -31,6 +31,7 @@ fr: reserve_a_machine: "Réserver une machine" trainings_registrations: "Inscriptions formations" events_registrations: "Inscriptions aux évènements" + reserve_a_space: "Réserver un espace" projects_gallery: "Galerie de projets" subscriptions: "Abonnements" public_calendar: "Calendrier" @@ -44,6 +45,7 @@ fr: subscriptions_and_prices: "Abonnements & Tarifs" manage_the_events: "Gérer les évènements" manage_the_machines: "Gérer les machines" + manage_the_spaces: "Gérer les espaces" manage_the_projects_elements: "Gérer les éléments projets" statistics: "Statistiques" customization: "Personnalisation" @@ -248,6 +250,12 @@ fr: you_can_shift_this_reservation_on_the_following_slots: "Vous pouvez déplacer cette réservation sur les créneaux suivants :" calendar: + # calendrier publique calendar: "Calendrier" show_no_disponible: "Afficher les crénaux non disponibles" filter-calendar: "Filtrer le calendrier" + + spaces_list: + # liste des espaces + the_spaces: "Les espaces" + add_a_space: "Ajouter un espace" diff --git a/config/routes.rb b/config/routes.rb index fc122e5ad..00691ad9a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -123,6 +123,7 @@ Rails.application.routes.draw do patch :reset_token, on: :member end resources :price_categories + resources :spaces # i18n get 'translations/:locale/:state' => 'translations#show', :constraints => { :state => /[^\/]+/ } # allow dots in URL for 'state'