Skip to content
New issue

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

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

Already on GitHub? # to your account

Cleaning the categories for alpha agenda #885

Draft
wants to merge 3 commits into
base: staging
Choose a base branch
from
Draft
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
3 changes: 1 addition & 2 deletions app/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ const ActivityCategories = [
'Algemeen',
'Sociëteit',
'Vorming',
'Dinsdagkring',
'Woensdagkring',
'Kring',
'ChOOSE',
'IFES',
'OZON',
Expand Down
33 changes: 24 additions & 9 deletions app/controllers/activities/ical.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import Controller from '@ember/controller';
import EditController from 'amber-ui/controllers/application/edit';
// eslint-disable-next-line ember/no-computed-properties-in-native-classes
import { computed } from '@ember/object';
import { inject as service } from '@ember/service';
import { ActivityCategories } from 'amber-ui/constants';
import { tracked } from '@glimmer/tracking';

export default class ActivitiesIcalController extends Controller {
export default class ActivitiesIcalController extends EditController {
@service session;

@tracked activityCategoryOptions;

constructor() {
Expand All @@ -24,22 +23,21 @@

@computed('activityCategoryOptions.@each.checked')
get categoriesParams() {
const selected = this.activityCategoryOptions
.filter((category) => category.checked)
.map((category) => category.value);
return `categories=${selected.join(',')}`;
return this.activityCategoryOptions
.filter(category => category.checked)

Check failure on line 27 in app/controllers/activities/ical.js

View workflow job for this annotation

GitHub Actions / Lint

Replace `category` with `(category)`
.map(category => category.value);

Check failure on line 28 in app/controllers/activities/ical.js

View workflow job for this annotation

GitHub Actions / Lint

Replace `category` with `(category)`

Check warning on line 28 in app/controllers/activities/ical.js

View check run for this annotation

Codecov / codecov/patch

app/controllers/activities/ical.js#L26-L28

Added lines #L26 - L28 were not covered by tests
}

get iCalBase() {
return `/ical/activities?key=${this.session.currentUser.icalSecretKey}&user_id=${this.session.currentUser.id}`;
}

get iCalURL() {
return `${window.location.origin}${this.iCalBase}&${this.categoriesParams}`;
return `${window.location.origin}${this.iCalBase}`;

Check warning on line 36 in app/controllers/activities/ical.js

View check run for this annotation

Codecov / codecov/patch

app/controllers/activities/ical.js#L36

Added line #L36 was not covered by tests
}

get webcalURL() {
return `webcal://${window.location.host}${this.iCalBase}&${this.categoriesParams}`;
return `webcal://${window.location.host}${this.iCalBase}`;

Check warning on line 40 in app/controllers/activities/ical.js

View check run for this annotation

Codecov / codecov/patch

app/controllers/activities/ical.js#L40

Added line #L40 was not covered by tests
}

_activityCategoryToOption(activityCategory) {
Expand All @@ -49,4 +47,21 @@
checked: true,
};
}

saveCategories = () => {
const { currentUser } = this.session;
const selectedCategories = this.categoriesParams;

Check warning on line 53 in app/controllers/activities/ical.js

View check run for this annotation

Codecov / codecov/patch

app/controllers/activities/ical.js#L51-L53

Added lines #L51 - L53 were not covered by tests

currentUser.set('icalCategories', selectedCategories);

Check warning on line 55 in app/controllers/activities/ical.js

View check run for this annotation

Codecov / codecov/patch

app/controllers/activities/ical.js#L55

Added line #L55 was not covered by tests

Check failure on line 56 in app/controllers/activities/ical.js

View workflow job for this annotation

GitHub Actions / Lint

Delete `··`
return currentUser.save()

Check failure on line 57 in app/controllers/activities/ical.js

View workflow job for this annotation

GitHub Actions / Lint

Insert `⏎······`

Check warning on line 57 in app/controllers/activities/ical.js

View check run for this annotation

Codecov / codecov/patch

app/controllers/activities/ical.js#L57

Added line #L57 was not covered by tests
.then(() => {
console.log('Categories saved successfully!');

Check warning on line 59 in app/controllers/activities/ical.js

View check run for this annotation

Codecov / codecov/patch

app/controllers/activities/ical.js#L59

Added line #L59 was not covered by tests
})
.catch((error) => {
console.error('Failed to save categories:', error);

Check warning on line 62 in app/controllers/activities/ical.js

View check run for this annotation

Codecov / codecov/patch

app/controllers/activities/ical.js#L62

Added line #L62 was not covered by tests
});
};

Check failure on line 64 in app/controllers/activities/ical.js

View workflow job for this annotation

GitHub Actions / Lint

Delete `⏎··⏎··`


}
1 change: 1 addition & 0 deletions app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default class User extends Model {
// Security properties
@attr otpRequired;
@attr icalSecretKey;
@attr icalCategories;
@attr webdavSecretKey;
@attr password;

Expand Down
12 changes: 9 additions & 3 deletions app/templates/activities/ical.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
uitgelegd.
</p>
</div>

<form class='row' id='activityCategoryForm'>
{{#each activityCategoryOptions as |opt|}}
{{#each this.activityCategoryOptions as |opt|}}
<div class='col-sm-12 col-md-3'>
<div class='form-check'>
<Input
Expand All @@ -34,6 +35,11 @@
</div>
</div>
{{/each}}
<div class="col-12 mt-3">
<button type="button" class="btn btn-primary" {{on "click" (fn this.saveCategories)}}>

Check failure on line 39 in app/templates/activities/ical.hbs

View workflow job for this annotation

GitHub Actions / Lint

`fn` helpers without additional arguments are not allowed
Opslaan
</button>
</div>
</form>

<hr />
Expand All @@ -51,8 +57,8 @@
anderen.
</b>
</div>
<p><a href='{{webcalURL}}'><code>{{iCalURL}}</code></a> </p>
<p><a href='{{this.webcalURL}}'><code>{{this.iCalURL}}</code></a></p>
</div>
</div>
</div>
</div>
</div>
3 changes: 1 addition & 2 deletions mirage/factories/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ export default Factory.extend({
'algemeen',
'sociëteit',
'vorming',
'dinsdagkring',
'woensdagkring',
'kring',
'choose',
'ifes',
'ozon',
Expand Down
Loading