Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort Anwesenheiten #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 12 additions & 2 deletions src/anw-single/anw-single.html
Original file line number Diff line number Diff line change
Expand Up @@ -554,12 +554,18 @@ <h1>Person entfernen?</h1>
* zeiten: ["15:00-16:00"]
* }
**/
person: Object,
person: {
type: Object,
notify: true
},

/**
* Key to the person this anw-single card represents.
**/
key: String,
key: {
type: String,
notify: true
},

/**
* If an error occurs this String will contain an error message to display to the user.
Expand Down Expand Up @@ -653,6 +659,10 @@ <h1>Person entfernen?</h1>
} else {
this.lastStatus = newStatus;
}

if(newStatus !== undefined) {
this.dispatchEvent(new CustomEvent('status-changed', { detail: { key: this.key, status: newStatus } }));
}
}

/**
Expand Down
33 changes: 25 additions & 8 deletions src/anwesenheit-app/anwesenheit-app.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ <h1 class="flex">Anwesenheit</h1>
<div class="layout horizontal wrap center-justified">

<template is="dom-if" if="[[personen]]">
<template is="dom-repeat" items="[[personen]]">
<anw-single on-delete="_onDeleteEntry" sound-enabled="{{soundEnabled}}" key="{{item}}">
<template is="dom-repeat" items="[[personen]]" sort="sortPersonen" observe="status">
<anw-single on-status-changed="_statusChanged" on-delete="_onDeleteEntry" sound-enabled="{{soundEnabled}}" key="{{item.key}}">
</anw-single>
</template>
</template>
Expand Down Expand Up @@ -158,7 +158,7 @@ <h1>Raum wechseln?</h1>
* @customElement
* @polymer
*/
class AnwesenheitApp extends Polymer.Element {
class AnwesenheitApp extends Polymer.MutableData(Polymer.Element) {
static get is() {
return 'anwesenheit-app';
}
Expand Down Expand Up @@ -206,8 +206,8 @@ <h1>Raum wechseln?</h1>
}

toBeAdded.forEach(element => {
if (!this.personen.includes(element)) {
this.push('personen', element);
if (!this.personen.some(e => e.key === element)) {
this.push('personen', {key: element, status: 2});
}
})
}
Expand All @@ -216,7 +216,7 @@ <h1>Raum wechseln?</h1>
var newurl = new URL(document.location.href.split("?")[0]);

this.personen.forEach(element => {
newurl.searchParams.append("track", element);
newurl.searchParams.append("track", element.key);
})

if (navigator.share !== undefined) {
Expand All @@ -239,17 +239,34 @@ <h1>Raum wechseln?</h1>
addEntry(event) {
// var personID = prompt("Bitte geben Sie die ID der Person ein, die sie hinzufügen wollen.");
if (this.personID !== null && typeof this.personID !== "undefined" && this.personID !== "") {
this.push('personen', this.personID);
this.push('personen', {key: this.personID, status: 2});
this.personID = undefined;
}
}

_onDeleteEntry(event) {
const personKey = event.detail.key;
const personIndex = this.personen.indexOf(personKey);
const personIndex = this.personen.indexOf(this.personen.find(pers => pers.key === personKey));
this.splice('personen', personIndex, personIndex + 1);
}

sortPersonen(a,b) {
if (a.status < b.status) return -1;
if (a.status > b.status) return 1;
return 0;
}

_statusChanged(event) {
const personState = event.detail;

const personIndex = this.personen.indexOf(this.personen.find(pers => pers.key === personState.key));
if(personState.status !== undefined){
this.set("personen." + personIndex + ".status", parseInt(personState.status))
} else {
this.set("personen." + personIndex + ".status", 2)
}
}

}

window.customElements.define(AnwesenheitApp.is, AnwesenheitApp);
Expand Down