1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-19 13:54:25 +01:00

[poc] show google agenda events in the public calendar

This commit is contained in:
Sylvain 2019-11-26 13:44:43 +01:00
parent 90b3564138
commit a9b1eabb2c
8 changed files with 46 additions and 2 deletions

View File

@ -152,3 +152,5 @@ gem 'sys-filesystem'
gem 'sha3'
gem 'repost'
gem 'icalendar'

View File

@ -191,6 +191,9 @@ GEM
multi_xml (>= 0.5.2)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
icalendar (2.5.3)
ice_cube (~> 0.16)
ice_cube (0.16.3)
ice_nine (0.11.2)
jaro_winkler (1.5.1)
jbuilder (2.5.0)
@ -497,6 +500,7 @@ DEPENDENCIES
forgery
friendly_id (~> 5.1.0)
has_secure_token
icalendar
jbuilder (~> 2.5)
jbuilder_cache_multi
jquery-rails

View File

@ -16,8 +16,8 @@
* Controller used in the public calendar global
*/
Application.Controllers.controller('CalendarController', ['$scope', '$state', '$aside', 'moment', 'Availability', 'Slot', 'Setting', 'growl', 'dialogs', 'bookingWindowStart', 'bookingWindowEnd', '_t', 'uiCalendarConfig', 'CalendarConfig', 'trainingsPromise', 'machinesPromise', 'spacesPromise',
function ($scope, $state, $aside, moment, Availability, Slot, Setting, growl, dialogs, bookingWindowStart, bookingWindowEnd, _t, uiCalendarConfig, CalendarConfig, trainingsPromise, machinesPromise, spacesPromise) {
Application.Controllers.controller('CalendarController', ['$scope', '$state', '$aside', 'moment', 'Availability', 'Slot', 'Setting', 'growl', 'dialogs', 'bookingWindowStart', 'bookingWindowEnd', '_t', 'uiCalendarConfig', 'CalendarConfig', 'trainingsPromise', 'machinesPromise', 'spacesPromise', 'externalsPromise',
function ($scope, $state, $aside, moment, Availability, Slot, Setting, growl, dialogs, bookingWindowStart, bookingWindowEnd, _t, uiCalendarConfig, CalendarConfig, trainingsPromise, machinesPromise, spacesPromise, externalsPromise) {
/* PRIVATE STATIC CONSTANTS */
let currentMachineEvent = null;
machinesPromise.forEach(m => m.checked = true);
@ -38,6 +38,9 @@ Application.Controllers.controller('CalendarController', ['$scope', '$state', '$
// List of spaces
$scope.spaces = spacesPromise.filter(t => !t.disabled);
// External ICS calendars
$scope.externals = externalsPromise;
// add availabilities source to event sources
$scope.eventSources = [];

View File

@ -638,6 +638,7 @@ angular.module('application.router', ['ui.router'])
trainingsPromise: ['Training', function (Training) { return Training.query().$promise; }],
machinesPromise: ['Machine', function (Machine) { return Machine.query().$promise; }],
spacesPromise: ['Space', function (Space) { return Space.query().$promise; }],
externalsPromise: ['Ical', function (Ical) { return Ical.get().$promise; }],
translations: ['Translations', function (Translations) { return Translations.query(['app.public.calendar']).$promise; }]
}
})

View File

@ -0,0 +1,5 @@
'use strict';
Application.Services.factory('Ical', ['$resource', function ($resource) {
return $resource('/api/ical/externals');
}]);

View File

@ -0,0 +1,19 @@
# frozen_string_literal: true
# API Controller for resources of type iCalendar
class API::IcalController < API::ApiController
respond_to :json
def externals
require 'net/http'
require 'uri'
ics = Net::HTTP.get(URI.parse('https://calendar.google.com/calendar/ical/sylvain%40sleede.com/public/basic.ics'))
require 'icalendar'
require 'icalendar/tzinfo'
cals = Icalendar::Calendar.parse(ics)
@events = cals.first.events
end
end

View File

@ -0,0 +1,8 @@
json.array!(@events) do |event|
json.id event.uid
json.title event.summary
json.start event.dtstart.iso8601
json.end event.dtend.iso8601
json.backgroundColor 'white'
json.borderColor '#214712'
end

View File

@ -112,6 +112,8 @@ Rails.application.routes.draw do
get 'first', action: 'first', on: :collection
end
get 'ical/externals' => 'ical#externals'
# for admin
resources :trainings do
get :availabilities, on: :member