mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-19 16:13:06 +00:00
feat: timetable module - schedule and calendar
This commit is contained in:
35
src/app/util/array-last.pipe.ts
Normal file
35
src/app/util/array-last.pipe.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {Injectable, Pipe, PipeTransform} from '@angular/core';
|
||||
import {last} from 'lodash-es';
|
||||
|
||||
/**
|
||||
* Get the last value of an array
|
||||
*/
|
||||
@Injectable()
|
||||
@Pipe({
|
||||
name: 'last',
|
||||
pure: true,
|
||||
})
|
||||
export class ArrayLastPipe implements PipeTransform {
|
||||
/**
|
||||
* Transform
|
||||
*/
|
||||
// tslint:disable-next-line:prefer-function-over-method
|
||||
transform<T>(value: T[]): T | undefined {
|
||||
return last(value);
|
||||
}
|
||||
}
|
||||
36
src/app/util/date-is-today.pipe.ts
Normal file
36
src/app/util/date-is-today.pipe.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {Injectable, Pipe, PipeTransform} from '@angular/core';
|
||||
import moment, {Moment, unitOfTime} from 'moment';
|
||||
|
||||
/**
|
||||
* Get the last value of an array
|
||||
*/
|
||||
@Injectable()
|
||||
@Pipe({
|
||||
name: 'dateIsThis',
|
||||
pure: false, // pure pipe can break in some change detection scenarios,
|
||||
// specifically, on the calendar view it causes it to stay true even when you navigate
|
||||
})
|
||||
export class DateIsThisPipe implements PipeTransform {
|
||||
/**
|
||||
* Transform
|
||||
*/
|
||||
// tslint:disable-next-line:prefer-function-over-method
|
||||
transform(value: Moment, granularity: unitOfTime.StartOf): boolean {
|
||||
return value.isSame(moment(moment.now()), granularity);
|
||||
}
|
||||
}
|
||||
34
src/app/util/nullish-coalecing.pipe.ts
Normal file
34
src/app/util/nullish-coalecing.pipe.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {Injectable, Pipe, PipeTransform} from '@angular/core';
|
||||
|
||||
/**
|
||||
* Get the last value of an array
|
||||
*/
|
||||
@Injectable()
|
||||
@Pipe({
|
||||
name: 'nullishCoalesce',
|
||||
pure: true,
|
||||
})
|
||||
export class NullishCoalescingPipe implements PipeTransform {
|
||||
/**
|
||||
* Transform
|
||||
*/
|
||||
// tslint:disable-next-line:prefer-function-over-method
|
||||
transform<T, G>(value: T, fallback: G): T | G {
|
||||
return value ?? fallback;
|
||||
}
|
||||
}
|
||||
25
src/app/util/util.module.ts
Normal file
25
src/app/util/util.module.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {NgModule} from '@angular/core';
|
||||
import {ArrayLastPipe} from './array-last.pipe';
|
||||
import {DateIsThisPipe} from './date-is-today.pipe';
|
||||
import {NullishCoalescingPipe} from './nullish-coalecing.pipe';
|
||||
|
||||
@NgModule({
|
||||
declarations: [ArrayLastPipe, DateIsThisPipe, NullishCoalescingPipe],
|
||||
exports: [ArrayLastPipe, DateIsThisPipe, NullishCoalescingPipe],
|
||||
})
|
||||
export class UtilModule {}
|
||||
Reference in New Issue
Block a user