Skip to content

Commit

Permalink
feat: added button to copy personalised webcal link
Browse files Browse the repository at this point in the history
  • Loading branch information
SilasPeters committed May 21, 2024
1 parent 78378d0 commit 70b86ad
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'icalendar_helper'

class CalendarsController < ActionController::Base

class Api::CalendarsController < ActionController::Base
# supply the personalised iCal feed from the user
# TODO supporting WebDAV might be nat, but not needed
def show
Expand All @@ -28,9 +27,15 @@ def show
# send_file calendar_path, type: 'text/calendar', disposition: 'attachment'
# else
# render json: { error: "Unkown hash" }, status: :not_found
# end
# end TODO 500 error if @member is empty
end

def index
@member = Member.find(current_user.credentials_id) # TODO gives 500 error when not logged in
render plain: "https://koala.svsticky.nl/api/calendar/pull/#{@member.calendar_id}" # TODO can this less hard-coded?
end

# Not exposed to API directly, but through #show
def create_calendar
@member = Member.find_by(calendar_id: params[:calendar_id])
events = @member.activities.map { |a| IcalendarHelper.activityToEvent(a) }
Expand Down
18 changes: 14 additions & 4 deletions app/javascript/src/members/activities/activities.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,25 @@ import { Activity } from "./activity.js";
var token, modal;

function copyICSToClipboard() {
/* Link to copy */
var copy_text =
"https://calendar.google.com/calendar/ical/stickyutrecht.nl_thvhicj5ijouaacp1elsv1hceo%40group.calendar.google.com/public/basic.ics";
new Clipboard("#copy-btn", {
text: function () {
return copy_text;
return "https://calendar.google.com/calendar/ical/stickyutrecht.nl_thvhicj5ijouaacp1elsv1hceo%40group.calendar.google.com/public/basic.ics";
},
});
}

function copyPersonalICSToClipboard() {
fetch("/api/calendar/fetch")
.then(response => response.text())
.then(icsFeed => {
new Clipboard("#copy-btn-personal", {
text: function () {
return icsFeed;
},
});
});
}

export function get_activity_container() {
return $("#activity-container");
}
Expand Down Expand Up @@ -244,6 +253,7 @@ $(document).on("ready page:load turbolinks:load", function () {
initialize_enrollment();
initialize_modal();
copyICSToClipboard();
copyPersonalICSToClipboard();
});

document.addEventListener("turbolinks:load", function () {
Expand Down
2 changes: 2 additions & 0 deletions app/views/members/activities/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
= I18n.t 'members.activities.index.activities_calendar'
%button.btn.btn-secondary#copy-btn{:type => 'button'}
= I18n.t 'members.activities.index.copy_ICS'
%button.btn.btn-secondary#copy-btn-personal{:type => 'button'}
= I18n.t 'members.activities.index.copy_ICS_personal'
- else
.alert.alert-warning= I18n.t('members.activities.index.no_activities')

Expand Down
5 changes: 3 additions & 2 deletions config/locales/members.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ en:
full: FULL!
index:
activities_calendar: Activities calendar
copy_ICS: Copy Webcal link
copy_ICS: Copy Webcal link for all activitites
copy_ICS_personal: Copy Personalised Webcal link
no_activities: There are no activities for which you can enroll at the moment
info:
more_info: More info
notes_mandatory: Extra info required!
home:
edit:
board: the board
board_only_change_info: Some data can't be edit by yourself (for example your name, date of birth and student number). If this needs to be updated please contact
board_only_change_info: Some data can't be edited by yourself (for example your name, date of birth and student number). If this needs to be updated please contact
download:
activities: Activities
address: Address
Expand Down
1 change: 1 addition & 0 deletions config/locales/members.nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ nl:
index:
activities_calendar: Activiteitenkalender
copy_ICS: Kopieer Webcal link
copy_ICS_personal: Kopieer gepersonaliseerde Webcal link
no_activities: Er zijn op het moment geen activiteiten waar je je voor kunt inschrijven
info:
more_info: Meer info
Expand Down
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Rails.application.routes.draw do
get 'calendar/:calendar_id', to: 'calendars#show', defaults: { format: 'ics' }

use_doorkeeper_openid_connect

constraints subdomain: ['intro', 'intro.dev'] do
Expand Down Expand Up @@ -126,6 +124,8 @@
end

scope 'api' do
get 'calendar/pull/:calendar_id', to: 'api/calendars#show', defaults: { format: 'ics' }
get 'calendar/fetch', to: 'api/calendars#index'
use_doorkeeper do
# skip_controllers :token_info, :applications, :authorized_applications
end
Expand Down

0 comments on commit 70b86ad

Please sign in to comment.