Skip to content

Commit

Permalink
Merge pull request #146 from bkd-mba-fbi/develop
Browse files Browse the repository at this point in the history
3.4.0
  • Loading branch information
schefbi authored Dec 16, 2022
2 parents fd0165d + 8448c86 commit 0d64833
Show file tree
Hide file tree
Showing 24 changed files with 619 additions and 235 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# kursausschreibung 3.3.4
# kursausschreibung 3.4.0
[![Build 🏭🚀](https://github.com/bkd-mba-fbi/kursausschreibung/actions/workflows/buildDeploy.yml/badge.svg)](https://github.com/bkd-mba-fbi/kursausschreibung/actions/workflows/buildDeploy.yml)

# Documentation
Expand Down Expand Up @@ -53,7 +53,7 @@ For one reason or another, some people can't connect to the registry via HTTPS.
* Visit your app at [http://localhost:4200](http://localhost:4200).
* Visit your tests at [http://localhost:4200/tests](http://localhost:4200/tests).

## Code Generators
### Code Generators

Make use of the many generators for code, try `ember help generate` for more details

Expand Down
23 changes: 22 additions & 1 deletion app/components/event-list-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import Component from '@ember/component';
import { oneWay } from '@ember/object/computed';
import { observer } from '@ember/object';
import { setParameterByName, getParameterByName } from 'kursausschreibung/framework/url-helpers';
import { sortAs } from '../framework/gui-helpers';
import { getSortAs } from '../framework/storage';
import settings from '../framework/settings';

// tests if a query matches a value
function match(value, query) {
Expand All @@ -25,8 +28,22 @@ export default Component.extend({

willRender() {
this.send('queryChanged');

let sortOptions = [];
if(settings.sortOptions === undefined) {
sortOptions.push({key:'error', value:'configure key sortoptions array in settings'});
} else {
settings.sortOptions.forEach(option => {
sortOptions.push({key:option, value:"sort"+option});
});
}
this.set('sortOptions',sortOptions);
},

didRender() {
document.getElementById('sortList').value = getSortAs();
},

filteredEvents: oneWay('events'),

keyUp(){
Expand Down Expand Up @@ -57,6 +74,10 @@ export default Component.extend({
);

this.get('queryChanged')(query);
},
sortBy(value) {
sortAs(value);
}
}
},

});
18 changes: 18 additions & 0 deletions app/components/list-pagination.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Component from '@ember/component';
import { computed } from '@ember/object';
import settings from 'kursausschreibung/framework/settings';
import { displayAsGrid } from 'kursausschreibung/framework/gui-helpers';
import {getListViewGrid} from 'kursausschreibung/framework/storage';

// pages to show before and after the current page
let n = 2;
Expand Down Expand Up @@ -83,4 +85,20 @@ export default Component.extend({

return eventfilterCodes.length === 1 ? null : eventfilterCodes;
}),

actions: {
grid() {
displayAsGrid(true);
},
list() {
displayAsGrid(false);
}
},

didRender(){
var listViewGrid = getListViewGrid();
listViewGrid = listViewGrid === null ? settings.displayGrid : getListViewGrid();
displayAsGrid(listViewGrid);
}

});
15 changes: 15 additions & 0 deletions app/framework/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import appConfig from './app-config';
import { getAccessToken } from './storage';
import { Promise } from 'rsvp';
import { getCorrectApiUrl } from './url-helpers';
import { getString } from 'kursausschreibung/framework/translate';

let accessToken = null;

Expand Down Expand Up @@ -204,6 +205,20 @@ export function postSubscriptionDetailsFiles(data,file) {
let locationHeader = xhr.getResponseHeader('location');
let arrayBuffer = base64ToArrayBuffer(file.fileAsBase64.substring(file.fileAsBase64.indexOf('base64,')+7,file.fileAsBase64.length));
return put(getCorrectApiUrl(locationHeader), arrayBuffer, true);

}).catch(error => {

if (error instanceof Error) {
console.error(error); // eslint-disable-line no-console
}

let message = '';
try {
message = error.responseJSON.Issues[0].Message;
} catch (exception) {
message = window.kursausschreibung.subscriptionFilesUploadFailed = getString('subscriptionFilesUploadFailed');
}
throw { message: message };
});
}
/**
Expand Down
65 changes: 65 additions & 0 deletions app/framework/gui-helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import {setListViewGrid, setSortAs} from 'kursausschreibung/framework/storage';

/**
* sort value set localStroage sortAs and reload
* @param {string} value
*/
export function sortAs(value) {
setSortAs(value);
window.location.reload();
}


/**
* display eventlist as grid or list
* true > grid
* false > list
* @param {boolean} bool
*/
export function displayAsGrid(bool) {
var list = document.getElementById('list-cards');
var btGrid = document.getElementById('bt-grid');
var btList = document.getElementById('bt-list');

if (typeof bool === "boolean") {
setListViewGrid(bool);
} else {
setListViewGrid(false);
}

if(bool) {
list.classList.add('uk-grid');
list.classList.add('uk-grid-match');
list.classList.add('uk-grid-stack');
list.classList.add('uk-child-width-1-2@m');
list.classList.add('uk-child-width-1-3@l');
list.classList.remove('uk-list-divider');
list.classList.remove('uk-list');
btGrid.classList.add('active-tab');
btList.classList.remove('active-tab');

} else {
list.classList.add('uk-list-divider');
list.classList.add('uk-list');
list.classList.remove('uk-grid');
list.classList.remove('uk-grid-match');
list.classList.remove('uk-grid-stack');
list.classList.remove('uk-child-width-1-2@m');
list.classList.remove('uk-child-width-1-3@l');
btList.classList.add('active-tab');
btGrid.classList.remove('active-tab');
}
for (const child of list.children) {

if(bool) {
child.classList.add('uk-card');
child.classList.add('uk-card-body');
child.classList.add('card-list');
} else {
child.classList.remove('uk-card');
child.classList.remove('uk-card-body');
child.classList.remove('card-list');
}
}

}
40 changes: 40 additions & 0 deletions app/framework/seo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { getRootModulUrl } from "./url-helpers";

/**
* create a json-ld element in head of document with schema.org course.
* @param {object} allevents from getAllEvents()
*/
export function setJsonLd(allEvents) {

let ld = [];
let areas = Object.values(allEvents.areas);

areas.forEach(area => {
area.events.forEach(event => {
let course = {};
course['@context'] = 'https://schema.org/';
course['@type'] = 'Course';
course['name'] = event.Designation;
course['description'] = getDescription(event);
course['courseCode'] = event.Number;
course['provider'] = {type: 'Organization', name: event.Host};
course['url'] = getRootModulUrl() + '#/uid/' + event.Id;

ld.push(course);
});

});

const script = document.createElement('script');
script.type = 'application/ld+json';
script.innerHTML = JSON.stringify(ld);
document.getElementsByTagName('head')[0].appendChild(script);
}

function getDescription(event){
let description = event.EventCategory + ';';
event.texts.forEach(text => {
description = description + text.label + ':' + text.memo + ';';
});
return description;
}
12 changes: 9 additions & 3 deletions app/framework/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,26 @@ let [
[getCulture, setCulture],
[getAccessToken, setAccessToken],
[getRefreshToken, setRefreshToken],
[getTokenExpire, setTokenExpire]
[getTokenExpire, setTokenExpire],
[getListViewGrid, setListViewGrid],
[getSortAs, setSortAs]
] = [
'uiCulture',
'CLX.LoginToken',
'CLX.RefreshToken',
'CLX.TokenExpire',
'kursausschreibung.dataToSubmit'
'listViewGrid',
'sortAs',
'kursausschreibung.dataToSubmit',
].map(key => [getItem.bind(null, key), setItem.bind(null, key)]);

export {
getCulture, setCulture,
getAccessToken, setAccessToken,
getRefreshToken, setRefreshToken,
getTokenExpire, setTokenExpire
getTokenExpire, setTokenExpire,
getListViewGrid, setListViewGrid,
getSortAs, setSortAs
};

export function getDataToSubmit(){
Expand Down
19 changes: 16 additions & 3 deletions app/framework/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { formatDate, combineDate, isInSubscriptionRange, removeMinutes, eventSta
import { all } from 'rsvp';
import settings from './settings';
import { getLanguage, getString } from './translate';
import { getSortAs } from './storage';
import format from 'date-fns/format';

let initialized = false;
Expand Down Expand Up @@ -65,8 +66,13 @@ export function init() {
events = filterEvents(events, language, eventCodes);

// sort events
if (settings.sortEventList !== null) {
events = A(events).sortBy(settings.sortEventList);
var sortAs = getSortAs();
if(sortAs === null) {
if (settings.sortEventList !== null) {
events = A(events).sortBy(settings.sortEventList);
}
} else {
events = A(events).sortBy(sortAs);
}

// prepare events
Expand Down Expand Up @@ -168,6 +174,7 @@ function addLocationsToEvents(eventLocations) {
* @param {object[]} lessons lessons returned by the API
*/
function addLessonsToEvents(lessons) {

lessons.forEach(function (lesson) {
if (!eventsById.hasOwnProperty(lesson.EventId)) {
return;
Expand All @@ -178,6 +185,12 @@ function addLessonsToEvents(lessons) {
lesson.TimeTo = formatDate(lesson.DateTimeTo, 'LT');

eventsById[lesson.EventId].lessons.push(lesson);
if (eventsById[lesson.EventId].lessons.length > settings.howManyLessonsShow) {
eventsById[lesson.EventId].lessonsCollaps = true;
} else {
eventsById[lesson.EventId].lessonsCollaps = false;
}

});
}

Expand Down Expand Up @@ -423,7 +436,7 @@ function addDisplayData(event) {
SubscriptionFrom: formatDate(event.SubscriptionFrom, 'LLL'),
SubscriptionTo: formatDate(event.SubscriptionTo, 'LLL'),

Price: 'CHF ' + event.Price
Price: event.Price === 0.0000 || event.Price === null ? null : 'CHF ' + event.Price
});
}

Expand Down
15 changes: 11 additions & 4 deletions app/framework/url-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function setParameterByName(name,value, url) {
return url;
}

let params = decodeURI(url).split('?');
let params = decodeURIComponent(url).split('?');
let paramsLength = params.length;
params = params.length === 3 ? params[1] + '?' + params[2] : params[1];

Expand All @@ -68,8 +68,8 @@ export function setParameterByName(name,value, url) {
} else {
params = name +'='+ value;
}

window.location.href = encodeURI(url.split('?')[0] + '?' + params);
window.location.href = url.split('?')[0] + '?' + params;
}

/**
Expand All @@ -82,6 +82,13 @@ export function getCorrectApiUrl(url){
var getIndex = url.split('/')[apiUriSplitLength];
return url.substring(url.indexOf(getIndex),url.length);
} else {
return url;
return '..' + url;
}
}

/**
* Get the first term window.location.href split by #
*/
export function getRootModulUrl(){
return window.location.href.split('#')[0];
}
8 changes: 5 additions & 3 deletions app/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import $ from 'jquery';
import { init as initStore, getAllEvents, getEventById } from 'kursausschreibung/framework/store';
import { getDataToSubmit } from 'kursausschreibung/framework/storage';
import { autoCheckForLogin } from 'kursausschreibung/framework/login-helpers';
import { setJsonLd } from '../framework/seo';

export default Route.extend({
beforeModel() {
Expand All @@ -17,7 +18,7 @@ export default Route.extend({
// reroute to the confirmation page if there is data that has to be submitted
let dataToSubmit = getDataToSubmit();

if (dataToSubmit !== null) {
if (dataToSubmit !== undefined) {
let event = getEventById(dataToSubmit.eventId);
this.replaceWith('list.category.event.confirmation', event.areaKey, event.categoryKey, event.Id);
}
Expand All @@ -33,7 +34,8 @@ export default Route.extend({
model() {
// remove loader
$('#kursausschreibung-loading').remove();

return getAllEvents();
let allEvents = getAllEvents();
setJsonLd(allEvents);
return allEvents;
}
});
3 changes: 2 additions & 1 deletion app/routes/list/category/event/confirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { postPerson, putPerson, postAddress, postSubscription, postSubscriptionD
import { autoCheckForLogin } from 'kursausschreibung/framework/login-helpers';
import settings from 'kursausschreibung/framework/settings';
import { SUBSCRIPTION_DETAIL_ALLOW_MULTIPLE_PEOPLE } from 'kursausschreibung/framework/api';
import { getString } from 'kursausschreibung/framework/translate';

export default Route.extend({
model() {
Expand Down Expand Up @@ -94,7 +95,7 @@ export default Route.extend({
try {
message = error.responseJSON.Issues[0].Message;
} catch (exception) {
// ignore exception
message = getString('subscriptionFailed');
}
throw { message: message };
});
Expand Down
Loading

0 comments on commit 0d64833

Please sign in to comment.