Compare commits

...

8 Commits

Author SHA1 Message Date
09de4fd033 feat: outdated version handling 2023-10-05 09:56:25 +02:00
Rainer Killinger
cb196afded feat: communicate outdated app/api client version 2023-10-02 08:48:07 +00:00
e0b7e616b3 fix: live update distance in list items 2023-09-21 09:38:52 +00:00
38fb7a398d fix: long branch names prevent review deployment 2023-09-21 09:55:35 +02:00
a99e08cd68 refactor: change opening hours handling
fix: opening hours not updating
feat: lazy-load opening hours module
feat: add e2e tests for opening hours
refactor: migrate opening hours to on-push change detection
feat: show exact minutes in opening hours starting one hour before next change
2023-09-21 09:55:35 +02:00
a5c9d22016 feat: add external directions referral
feat: change map page
feat: add error handling and timeout to location fetching in directions

resolves #124
resolves #122
2023-09-15 18:52:28 +00:00
3c49c4cf6d fix: route stack service causes needless network traffic 2023-09-06 15:29:47 +02:00
f2c4ee308f feat: share loaded data to detail views across routes 2023-09-06 14:52:02 +02:00
127 changed files with 1393 additions and 1777 deletions

View File

@@ -0,0 +1,5 @@
---
'@openstapps/app': minor
---
Detail views now won't load data again if it is being navigated to from a list item

View File

@@ -0,0 +1,11 @@
---
'@openstapps/app': patch
---
Refactored Opening Hours
- Migrated Opening Hours to use OnPush change detection
- Fixed a bug where opening hours would not update correctly
- Lazy-load opening hours module to keep it out of the main bundle
- Added e2e tests to verify functionality
- Changed live update status to show exact minutes starting one hour before the next change

View File

@@ -0,0 +1,5 @@
---
'@openstapps/app': patch
---
Fixed distance not updating in list items

View File

@@ -0,0 +1,5 @@
---
'@openstapps/app': minor
---
Add directions to inPlace and place list items

View File

@@ -0,0 +1,8 @@
---
'@openstapps/app': minor
---
Adjust map button and item behavior on different screen sizes
- Small screens will show the item without margins below the map actions
- Large screens will show the list item on the left side

View File

@@ -0,0 +1,5 @@
---
'@openstapps/app': minor
---
Queue config update for next launch to not block app launches

View File

@@ -0,0 +1,5 @@
---
'@openstapps/app': patch
---
Fixed an issue that caused double and triple loading of data detail items through the route stack service

View File

@@ -0,0 +1,5 @@
---
'@openstapps/app': minor
---
Map items are now native list items

View File

@@ -0,0 +1,5 @@
---
'@openstapps/proxy': minor
---
Send 426 to outdated clients instead of 404

View File

@@ -80,7 +80,7 @@ build:
rules: &deploy-rules
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
variables:
DEPLOY_ID: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
DEPLOY_ID: $CI_MERGE_REQUEST_IID
- if: $CI_COMMIT_BRANCH == 'main'
variables:
DEPLOY_ID: production

View File

@@ -31,10 +31,11 @@ To Provide your own configuration file you can create a `default.json` file in t
## Status Codes
- OutdatedVersions return a `HTTP 404`
- ActiveVersions return a `HTTP 503` if currently unavailable or the given code by running backend-node
- Unsupported versions (not configured as outdated or active) return a `HTTP 404`
- Successfull reponses come with a `HTTP 200`
- No version header given returns a `HTTP 300`
- ActiveVersions return a `HTTP 503` if currently unavailable or the given code by running backend-node
- OutdatedVersions return a `HTTP 426`
- Unsupported versions (not configured as outdated or active) return a `HTTP 426`
**NOTE:** The default configuration expects the client to set a version header: `X-StApps-Version=<version of app>`

View File

@@ -14,9 +14,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// ESM is not supported, and cts is not detected, so we use type-checked cjs instead.
/** @type {import('../src/common').ConfigFile} */
const configFile = {
module.exports = {
activeVersions: ['1\\.0\\.\\d+', '2\\.0\\.\\d+'],
hiddenRoutes: ['/bulk'],
logFormat: 'default',
@@ -31,5 +30,3 @@ const configFile = {
dhparam: '/etc/nginx/certs/dhparam.pem',
},
};
export default configFile;

View File

@@ -19,14 +19,15 @@ location {{{ route }}} {
return 300 'You have to supply a client/app version via the X-StApps-Version header!';
}
# Version is unsupported or never existed
# Version is unsupported by now or never existed (App/Client has to update)
if ($proxyurl = unsupported) {
{{{ cors }}}
return 404;
return 426;
}
# The version existed, but is outdated now (App should update)
# The version existed, but is outdated now (App/Client should update)
if ($proxyurl = outdated) {
return 404;
{{{ cors }}}
return 426;
}
# The version is correct, but backend is not responding
if ($proxyurl = unavailable) {

View File

@@ -34,10 +34,12 @@
"build": "tsup-node --dts",
"build:docker": "docker build -t openstapps:proxy ../../.deploy/proxy",
"deploy": "pnpm --prod --filter=@openstapps/proxy deploy ../../.deploy/proxy",
"dev": "tsup --watch --onSuccess \"pnpm run start\"",
"format": "prettier . -c --ignore-path ../../.gitignore",
"format:fix": "prettier --write . --ignore-path ../../.gitignore",
"lint": "eslint --ext .ts src/",
"lint:fix": "eslint --fix --ext .ts src/",
"start": "node app.js",
"test": "c8 mocha"
},
"dependencies": {

View File

@@ -37,7 +37,7 @@ const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
* Reads the container information from the docker socket and updates the nginx config if necessary
*/
async function updateNginxConfig() {
const containers = await getContainers();
const containers = await getContainers(process.env.DOCKER_SOCKET);
const containerHash = containers
.map((container: ContainerInfo) => {
@@ -78,4 +78,4 @@ async function updateNginxConfig() {
// start the process that checks the docker socket periodically
// eslint-disable-next-line unicorn/prefer-top-level-await
updateNginxConfig();
await updateNginxConfig();

View File

@@ -1,7 +1,7 @@
version: '3.7'
services:
database:
image: registry.gitlab.com/openstapps/openstapps/database:2.0.0
image: registry.gitlab.com/openstapps/openstapps/database:3.0.0-next.4
volumes:
- ./database:/usr/share/elasticsearch/data
expose:
@@ -9,7 +9,7 @@ services:
restart: unless-stopped
backend:
image: registry.gitlab.com/openstapps/openstapps/backend:3.0.0-next.0
image: registry.gitlab.com/openstapps/openstapps/backend:3.0.0-next.4
environment:
ES_ADDR: "http://database:9200"
NODE_CONFIG_ENV: "elasticsearch"
@@ -27,17 +27,17 @@ services:
- database
api:
image: registry.gitlab.com/openstapps/openstapps/api:3.0.0-next.0
image: registry.gitlab.com/openstapps/openstapps/api:3.0.0-next.4
links:
- "backend"
minimal-connector:
image: registry.gitlab.com/openstapps/minimal-connector:core-0.23
image: registry.gitlab.com/openstapps/openstapps/minimal-connector:3.0.0-next.4
container_name: minimal-connector-0.23
command: ["http://backend:3000", "minimal-connector", "f-u"]
app:
image: registry.gitlab.com/openstapps/app/executable:core-0.23
image: registry.gitlab.com/openstapps/openstapps/app:3.0.0-next.4
expose:
- 8100
ports:

View File

@@ -15,8 +15,12 @@
buildToolsVersions = [ "${buildToolsVersion}" ];
platformVersions = [ "32" ];
};
cypress = prev.cypress.overrideAttrs(prev: {
version = "12.17.1";
cypress = prev.cypress.overrideAttrs(cyPrev: rec {
version = "13.2.0";
src = prev.fetchzip {
url = "https://cdn.cypress.io/desktop/${version}/linux-x64/cypress.zip";
hash = "sha256-9o0nprGcJhudS1LNm+T7Vf0Dwd1RBauYKI+w1FBQ3ZM=";
};
});
})
];

View File

@@ -8,7 +8,7 @@
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"project": ["tsconfig.json", "tsconfig.spec.json", "e2e/tsconfig.e2e.json"],
"project": ["tsconfig.json", "tsconfig.spec.json", "cypress/tsconfig.json"],
"createDefaultProgram": true
},
"extends": [

View File

@@ -49,10 +49,16 @@ The command `ionic cordova run ios` runs into the error `/platforms/ios/build/em
The browser doesn't open or the tests don't connect to a browser
#### Cause
Cypress was installed to a read-only location, see
[this issue](https://github.com/cypress-io/cypress/issues/18893).
This can be the case if you use NixOS.
#### Solution
Delete the Cypress config file
Make sure the cypress folder is writable before each launch
```shell
rm -rf ~/.config/Cypress
chmod -R +rw ~/.config/Cypress
```

View File

@@ -182,6 +182,7 @@
"builder": "@cypress/schematic:cypress",
"options": {
"devServerTarget": "app:serve",
"liveReload": false,
"watch": true,
"headless": false
},

View File

@@ -0,0 +1,141 @@
describe('opening hours', () => {
beforeEach(function () {
cy.intercept('POST', 'https://mobile.server.uni-frankfurt.de/search', {
fixture: 'search/types/canteen/canteen-search-result.json',
}).as('search');
});
it('should specify relative closing time', () => {
cy.clock(new Date(2023, 9, 16, 15, 29), ['Date']);
cy.visit('/canteen');
cy.get('stapps-opening-hours')
.first()
.should('contain', 'Geöffnet')
.should('contain', 'Schließt heute um 22:00');
});
it('should specify relative opening time', () => {
cy.clock(new Date(2023, 9, 16, 6, 29), ['Date']);
cy.visit('/canteen');
cy.get('stapps-opening-hours')
.first()
.should('contain', 'Geschlossen')
.should('contain', 'Öffnet heute um 08:30');
});
it('should specify soon opening time', () => {
cy.clock(new Date(2023, 9, 16, 8, 0), ['Date']);
cy.visit('/canteen');
cy.get('stapps-opening-hours')
.first()
.should('contain', 'Geschlossen')
.should('contain', 'Öffnet in 30 Minuten');
});
it('should specify soon closing time', () => {
cy.clock(new Date(2023, 9, 16, 21, 30), ['Date']);
cy.visit('/canteen');
cy.get('stapps-opening-hours')
.first()
.should('contain', 'Geöffnet')
.should('contain', 'Schließt in 30 Minuten');
});
it('should update the soon closing time every minute', () => {
cy.clock(new Date(2023, 9, 16, 21, 30));
cy.visit('/canteen');
cy.tick(500);
cy.get('stapps-opening-hours')
.first()
.should('contain', 'Geöffnet')
.should('contain', 'Schließt in 30 Minuten');
cy.tick(60_000);
cy.tick(50);
cy.get('stapps-opening-hours')
.first()
.should('contain', 'Geöffnet')
.should('contain', 'Schließt in 29 Minuten');
});
it('should update the status when it changes', () => {
cy.clock(new Date(2023, 9, 16, 21, 59));
cy.visit('/canteen');
cy.tick(500);
cy.get('stapps-opening-hours')
.first()
.should('contain', 'Geöffnet')
.should('contain', 'Schließt in 1 Minute');
cy.tick(60_000);
cy.get('stapps-opening-hours')
.first()
.should('contain', 'Geschlossen')
.should('contain', 'Öffnet morgen um 08:30');
});
// This one takes long to execute!
it('should update as expected', () => {
cy.clock(new Date(2023, 9, 16, 20, 59));
cy.visit('/canteen');
cy.tick(500);
cy.get('stapps-opening-hours')
.first()
.should('contain', 'Geöffnet')
.should('contain', 'Schließt heute um 22:00');
cy.tick(60_000);
cy.get('stapps-opening-hours')
.first()
.should('contain', 'Geöffnet')
.should('contain', 'Schließt in 60 Minuten');
cy.tick(30 * 60_000);
cy.get('stapps-opening-hours')
.first()
.should('contain', 'Geöffnet')
.should('contain', 'Schließt in 30 Minuten');
cy.tick(30 * 60_000);
cy.get('stapps-opening-hours')
.first()
.should('contain', 'Geschlossen')
.should('contain', 'Öffnet morgen um 08:30');
cy.tick(9.5 * 60 * 60_000);
cy.get('stapps-opening-hours')
.first()
.should('contain', 'Geschlossen')
.should('contain', 'Öffnet in 60 Minuten');
cy.tick(30 * 60_000);
cy.get('stapps-opening-hours')
.first()
.should('contain', 'Geschlossen')
.should('contain', 'Öffnet in 30 Minuten');
cy.tick(30 * 60_000);
cy.get('stapps-opening-hours')
.first()
.should('contain', 'Geöffnet')
.should('contain', 'Schließt heute um 22:00');
// Long tick warps will cause network requests to time out
cy.get('@consoleError').invoke('resetHistory');
});
});

View File

@@ -31,36 +31,24 @@
// When a command from ./commands is ready to use, import with `import './commands'` syntax
// import './commands';
beforeEach(async function () {
let databases: string[];
if (window.indexedDB.databases) {
databases = (await window.indexedDB.databases()).map(it => it.name);
console.log('Trying to clear all databases');
} else {
console.log("Browser doesn't support database enumeration, deleting just ionic storage");
databases = ['_ionicstorage'];
}
for (const database of databases) {
if (database) {
console.log(`Deleting database ${database}`);
await new Promise(resolve => (window.indexedDB.deleteDatabase(database).onsuccess = resolve));
console.log(`Deleted database ${database}`);
}
}
beforeEach(function () {
cy.wrap(
new Promise(resolve => {
window.indexedDB.deleteDatabase('_ionicstorage').onsuccess = resolve;
}),
);
});
Cypress.on('window:before:load', window => {
// Fake that user is using its browser in german language
// Fake that user is using its browser in German
Object.defineProperty(window.navigator, 'language', {value: 'de-DE'});
Object.defineProperty(window.navigator, 'languages', [{value: 'de-DE'}]);
// Fail tests on console error
cy.stub(window.console, 'error').callsFake(message => {
// log out to the terminal
cy.now('task', 'error', message);
// log to Command Log and fail the test
throw new Error(message);
});
cy.spy(window.console, 'error').as('consoleError');
});
afterEach(function () {
cy.get('@consoleError').should('not.have.been.called');
});
Cypress.on('uncaught:exception', error => {

View File

@@ -63,6 +63,7 @@
"@awesome-cordova-plugins/core": "5.45.0",
"@capacitor/app": "4.1.1",
"@capacitor/browser": "4.1.0",
"@capacitor/clipboard": "4.1.0",
"@capacitor/core": "4.6.1",
"@capacitor/device": "4.1.0",
"@capacitor/dialog": "4.1.0",
@@ -87,8 +88,11 @@
"@openstapps/collection-utils": "workspace:*",
"@openstapps/core": "workspace:*",
"@transistorsoft/capacitor-background-fetch": "1.0.2",
"@types/dom-view-transitions": "1.0.1",
"capacitor-secure-storage-plugin": "0.8.1",
"cordova-plugin-calendar": "5.1.6",
"date-fns": "2.30.0",
"ngx-date-fns": "10.0.1",
"deepmerge": "4.3.1",
"form-data": "4.0.0",
"geojson": "0.5.0",
@@ -146,7 +150,7 @@
"@typescript-eslint/eslint-plugin": "5.60.1",
"@typescript-eslint/parser": "5.60.1",
"cordova-res": "0.15.4",
"cypress": "12.17.1",
"cypress": "13.2.0",
"eslint": "8.43.0",
"eslint-plugin-jsdoc": "46.4.2",
"eslint-plugin-prettier": "4.2.1",

View File

@@ -21,17 +21,13 @@ import {RouteReuseStrategy} from '@angular/router';
import {IonicModule, IonicRouteStrategy, Platform} from '@ionic/angular';
import {TranslateLoader, TranslateModule, TranslateService} from '@ngx-translate/core';
import {TranslateHttpLoader} from '@ngx-translate/http-loader';
import moment from 'moment';
import 'moment/min/locales';
import {LoggerModule, NGXLogger, NgxLoggerLevel} from 'ngx-logger';
import {LoggerModule, NgxLoggerLevel} from 'ngx-logger';
import SwiperCore, {FreeMode, Navigation} from 'swiper';
import {environment} from '../environments/environment';
import {AppRoutingModule} from './app-routing.module';
import {AppComponent} from './app.component';
import {CatalogModule} from './modules/catalog/catalog.module';
import {ConfigModule} from './modules/config/config.module';
import {ConfigProvider} from './modules/config/config.provider';
import {DashboardModule} from './modules/dashboard/dashboard.module';
import {DataModule} from './modules/data/data.module';
import {HebisModule} from './modules/hebis/hebis.module';
@@ -40,11 +36,9 @@ import {MenuModule} from './modules/menu/menu.module';
import {NewsModule} from './modules/news/news.module';
import {ScheduleModule} from './modules/schedule/schedule.module';
import {SettingsModule} from './modules/settings/settings.module';
import {SettingsProvider} from './modules/settings/settings.provider';
import {StorageModule} from './modules/storage/storage.module';
import {ThingTranslateModule} from './translation/thing-translate.module';
import {UtilModule} from './util/util.module';
import {initLogger} from './_helpers/ts-logger';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {AboutModule} from './modules/about/about.module';
import {FavoritesModule} from './modules/favorites/favorites.module';
@@ -54,78 +48,22 @@ import {DebugDataCollectorService} from './modules/data/debug-data-collector.ser
import {AuthModule} from './modules/auth/auth.module';
import {BackgroundModule} from './modules/background/background.module';
import {LibraryModule} from './modules/library/library.module';
import {StorageProvider} from './modules/storage/storage.provider';
import {AssessmentsModule} from './modules/assessments/assessments.module';
import {ServiceHandlerInterceptor} from './_helpers/service-handler.interceptor';
import {RoutingStackService} from './util/routing-stack.service';
import {SCSettingValue} from '@openstapps/core';
import {DefaultAuthService} from './modules/auth/default-auth.service';
import {PAIAAuthService} from './modules/auth/paia/paia-auth.service';
import {IonIconModule} from './util/ion-icon/ion-icon.module';
import {NavigationModule} from './modules/menu/navigation/navigation.module';
import {browserFactory, SimpleBrowser} from './util/browser.factory';
import {ConfigProvider} from './modules/config/config.provider';
import {SettingsProvider} from './modules/settings/settings.provider';
import {TranslateServiceWrapper} from './translation/translate-service-wrapper';
import {DefaultAuthService} from './modules/auth/default-auth.service';
import {PAIAAuthService} from './modules/auth/paia/paia-auth.service';
import {StorageProvider} from './modules/storage/storage.provider';
registerLocaleData(localeDe);
SwiperCore.use([FreeMode, Navigation]);
/**
* Initializes data needed on startup
* @param storageProvider provider of the saved data (using framework's storage)
* @param logger TODO
* @param settingsProvider provider of settings (e.g. language that has been set)
* @param configProvider TODO
* @param translateService TODO
* @param _routingStackService Just for init and to track the stack from the get go
*/
export function initializerFactory(
storageProvider: StorageProvider,
logger: NGXLogger,
settingsProvider: SettingsProvider,
configProvider: ConfigProvider,
translateService: TranslateService,
_routingStackService: RoutingStackService,
defaultAuthService: DefaultAuthService,
paiaAuthService: PAIAAuthService,
) {
return async () => {
initLogger(logger);
await storageProvider.init();
await configProvider.init();
await settingsProvider.init();
try {
if (configProvider.firstSession) {
// set language from browser
await settingsProvider.setSettingValue(
'profile',
'language',
translateService.getBrowserLang() as SCSettingValue,
);
}
const languageCode = (await settingsProvider.getValue('profile', 'language')) as string;
// this language will be used as a fallback when a translation isn't found in the current language
translateService.setDefaultLang('en');
translateService.use(languageCode);
moment.locale(languageCode);
await defaultAuthService.init();
await paiaAuthService.init();
} catch (error) {
logger.warn(error);
}
};
}
/**
* TODO
* @param http TODO
*/
export function createTranslateLoader(http: HttpClient) {
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}
/**
* TODO
*/
@NgModule({
bootstrap: [AppComponent],
declarations: [AppComponent],
@@ -139,7 +77,6 @@ export function createTranslateLoader(http: HttpClient) {
BrowserAnimationsModule,
CatalogModule,
CommonModule,
ConfigModule,
DashboardModule,
DataModule,
HebisModule,
@@ -163,7 +100,9 @@ export function createTranslateLoader(http: HttpClient) {
loader: {
deps: [HttpClient],
provide: TranslateLoader,
useFactory: createTranslateLoader,
useFactory(http: HttpClient) {
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
},
},
}),
UtilModule,
@@ -173,6 +112,30 @@ export function createTranslateLoader(http: HttpClient) {
}),
],
providers: [
{
provide: APP_INITIALIZER,
useFactory:
(...providers: Array<{beforeAppInit(): Promise<void>}>) =>
async () => {
for (const provider of providers) {
await provider.beforeAppInit();
}
},
// Declare initialization (order matters)
deps: [
StorageProvider,
ConfigProvider,
SettingsProvider,
TranslateService,
DefaultAuthService,
PAIAAuthService,
],
multi: true,
},
{
provide: TranslateService,
useClass: TranslateServiceWrapper,
},
{
provide: RouteReuseStrategy,
useClass: IonicRouteStrategy,
@@ -186,21 +149,6 @@ export function createTranslateLoader(http: HttpClient) {
useFactory: browserFactory,
deps: [Platform],
},
{
provide: APP_INITIALIZER,
multi: true,
deps: [
StorageProvider,
NGXLogger,
SettingsProvider,
ConfigProvider,
TranslateService,
RoutingStackService,
DefaultAuthService,
PAIAAuthService,
],
useFactory: initializerFactory,
},
{
provide: HTTP_INTERCEPTORS,
useClass: ServiceHandlerInterceptor,

View File

@@ -0,0 +1,10 @@
/**
* Services or providers implementing this interface
* must be added to the `APP_INITIALIZER` deps
*/
export interface BeforeAppInit {
/**
* Any logic that has to run before the app is initialized
*/
beforeAppInit(): Promise<void>;
}

View File

@@ -14,10 +14,9 @@
*/
import {Component, OnInit} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {SCAboutPage, SCAppConfiguration} from '@openstapps/core';
import {ConfigProvider} from '../../config/config.provider';
import {SCAboutPage} from '@openstapps/core';
import packageJson from '../../../../../package.json';
import config from 'capacitor.config';
import {ConfigProvider} from '../../config/config.provider';
@Component({
selector: 'about-page',
@@ -27,15 +26,12 @@ import config from 'capacitor.config';
export class AboutPageComponent implements OnInit {
content: SCAboutPage;
appName = config.appName;
version = packageJson.version;
constructor(private readonly route: ActivatedRoute, private readonly configProvider: ConfigProvider) {}
constructor(readonly route: ActivatedRoute, readonly config: ConfigProvider) {}
async ngOnInit() {
ngOnInit() {
const route = this.route.snapshot.url.map(it => it.path).join('/');
this.content =
(this.configProvider.getValue('aboutPages') as SCAppConfiguration['aboutPages'])[route] ?? {};
this.content = this.config.app.aboutPages[route] ?? {};
}
}

View File

@@ -25,7 +25,7 @@
</ion-toolbar>
</ion-header>
<ion-content parallax *ngIf="content">
<ion-text>{{ appName }} v{{ version }}</ion-text>
<ion-text>{{ config.app.name }} v{{ version }}</ion-text>
<div class="page-content">
<about-page-content *ngFor="let element of content.content" [content]="element"></about-page-content>
</div>

View File

@@ -19,7 +19,6 @@ import {FormsModule} from '@angular/forms';
import {IonicModule} from '@ionic/angular';
import {TranslateModule} from '@ngx-translate/core';
import {ThingTranslateModule} from '../../translation/thing-translate.module';
import {ConfigProvider} from '../config/config.provider';
import {AboutPageComponent} from './about-page/about-page.component';
import {MarkdownModule} from 'ngx-markdown';
import {AboutPageContentComponent} from './about-page/about-page-content.component';
@@ -64,6 +63,5 @@ const settingsRoutes: Routes = [
ScrollingModule,
UtilModule,
],
providers: [ConfigProvider],
})
export class AboutModule {}

View File

@@ -13,11 +13,12 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {Injectable} from '@angular/core';
import {ConfigProvider} from '../config/config.provider';
import {SCAssessment, SCUuid} from '@openstapps/core';
import {DefaultAuthService} from '../auth/default-auth.service';
import {HttpClient} from '@angular/common/http';
import {uniqBy, keyBy} from '@openstapps/collection-utils';
import {firstValueFrom} from 'rxjs';
import {ConfigProvider} from '../config/config.provider';
/**
*
@@ -65,7 +66,7 @@ export class AssessmentsProvider {
cacheMaxAge = 15 * 60 * 1000;
constructor(
readonly configProvider: ConfigProvider,
readonly config: ConfigProvider,
readonly defaultAuth: DefaultAuthService,
readonly http: HttpClient,
) {}
@@ -91,21 +92,20 @@ export class AssessmentsProvider {
return this.cache;
}
const url = this.configProvider.config.app.features.extern?.hisometry.url;
const url = this.config.app.features.extern?.hisometry.url;
if (!url) throw new Error('Config lacks url for hisometry');
this.cache = this.http
.get<{data: SCAssessment[]}>(`${url}/${this.assessmentPath}`, {
this.cache = firstValueFrom(
this.http.get<{data: SCAssessment[]}>(`${url}/${this.assessmentPath}`, {
headers: {
Authorization: `Bearer ${accessToken ?? (await this.defaultAuth.getValidToken()).accessToken}`,
},
})
.toPromise()
.then(it => {
this.cacheTimestamp = Date.now();
}),
).then(it => {
this.cacheTimestamp = Date.now();
return it?.data ?? [];
});
return it?.data ?? [];
});
this.assessments = this.cache.then(toAssessmentMap);
return this.cache;

View File

@@ -17,7 +17,7 @@ import {Component, DestroyRef, inject, Input, OnInit, ViewChild} from '@angular/
import {ActivatedRoute} from '@angular/router';
import {AssessmentsProvider} from '../assessments.provider';
import {DataDetailComponent, ExternalDataLoadEvent} from '../../data/detail/data-detail.component';
import {NavController, ViewWillEnter} from '@ionic/angular';
import {NavController} from '@ionic/angular';
import {DataRoutingService} from '../../data/data-routing.service';
import {SCAssessment} from '@openstapps/core';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
@@ -27,7 +27,7 @@ import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
templateUrl: 'assessments-detail.html',
styleUrls: ['assessments-detail.scss'],
})
export class AssessmentsDetailComponent implements ViewWillEnter, OnInit {
export class AssessmentsDetailComponent implements OnInit {
destroy$ = inject(DestroyRef);
constructor(
@@ -67,8 +67,4 @@ export class AssessmentsDetailComponent implements ViewWillEnter, OnInit {
event.resolve(this.item);
});
}
async ionViewWillEnter() {
await this.detailComponent.ionViewWillEnter();
}
}

View File

@@ -61,6 +61,7 @@ export class AssessmentsSimpleDataListComponent implements OnInit {
queryParams: {
token: this.activatedRoute.snapshot.queryParamMap.get('token'),
},
state: {item: thing},
});
});
}

View File

@@ -71,6 +71,7 @@ export class AssessmentsPageComponent implements OnInit, AfterViewInit {
queryParams: {
token: this.activatedRoute.snapshot.queryParamMap.get('token'),
},
state: {item: thing},
});
});

View File

@@ -12,24 +12,18 @@
* 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} from '@angular/core';
import {IPAIAAuthAction} from './paia/paia-auth-action';
import {AuthActions, IAuthAction} from 'ionic-appauth';
import {TranslateService} from '@ngx-translate/core';
import {JSONPath} from 'jsonpath-plus';
import {
SCAuthorizationProvider,
SCAuthorizationProviderType,
SCUserConfiguration,
SCUserConfigurationMap,
} from '@openstapps/core';
import {ConfigProvider} from '../config/config.provider';
import {SCAuthorizationProviderType, SCUserConfiguration, SCUserConfigurationMap} from '@openstapps/core';
import {StorageProvider} from '../storage/storage.provider';
import {DefaultAuthService} from './default-auth.service';
import {PAIAAuthService} from './paia/paia-auth.service';
import {SimpleBrowser} from '../../util/browser.factory';
import {AlertController} from '@ionic/angular';
import {ConfigProvider} from '../config/config.provider';
const AUTH_ORIGIN_PATH = 'stapps.auth.origin_path';
@@ -37,23 +31,19 @@ const AUTH_ORIGIN_PATH = 'stapps.auth.origin_path';
providedIn: 'root',
})
export class AuthHelperService {
userConfigurationMap: SCUserConfigurationMap;
get userConfigurationMap(): SCUserConfigurationMap {
return this.config.auth.default!.endpoints.mapping;
}
constructor(
private translateService: TranslateService,
private configProvider: ConfigProvider,
private storageProvider: StorageProvider,
private defaultAuth: DefaultAuthService,
private paiaAuth: PAIAAuthService,
private browser: SimpleBrowser,
private alertController: AlertController,
) {
this.userConfigurationMap = (
this.configProvider.getAnyValue('auth') as {
default: SCAuthorizationProvider;
}
).default.endpoints.mapping;
}
private config: ConfigProvider,
) {}
public getAuthMessage(provider: SCAuthorizationProviderType, action: IAuthAction | IPAIAAuthAction) {
let message: string | undefined;

View File

@@ -175,7 +175,7 @@ export abstract class AuthService implements IAuthService {
public async init() {
this.setupAuthorizationNotifier();
this.loadTokenFromStorage();
await this.loadTokenFromStorage();
this.addActionObserver(this._actionHistory);
this.addActionObserver(this._session);
}

View File

@@ -12,29 +12,26 @@
* 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 {
AuthorizationRequestHandler,
AuthorizationServiceConfiguration,
JQueryRequestor,
LocalStorageBackend,
Requestor,
StorageBackend,
TokenRequestHandler,
} from '@openid/appauth';
import {AuthActionBuilder, Browser, DefaultBrowser, EndSessionHandler, UserInfoHandler} from 'ionic-appauth';
import {ConfigProvider} from '../config/config.provider';
import {SCAuthorizationProvider} from '@openstapps/core';
import {AuthActionBuilder, DefaultBrowser, EndSessionHandler, UserInfoHandler} from 'ionic-appauth';
import {getClientConfig, getEndpointsConfig} from './auth.provider.methods';
import {Injectable} from '@angular/core';
import {AuthService} from './auth.service';
import {ConfigProvider} from '../config/config.provider';
import {BeforeAppInit} from '../../before-app-init';
const TOKEN_RESPONSE_KEY = 'token_response';
@Injectable({
providedIn: 'root',
})
export class DefaultAuthService extends AuthService {
export class DefaultAuthService extends AuthService implements BeforeAppInit {
public localConfiguration: AuthorizationServiceConfiguration;
protected tokenHandler: TokenRequestHandler;
@@ -45,13 +42,17 @@ export class DefaultAuthService extends AuthService {
protected endSessionHandler: EndSessionHandler;
constructor(
protected browser: Browser = new DefaultBrowser(),
protected storage: StorageBackend = new LocalStorageBackend(),
protected requestor: Requestor = new JQueryRequestor(),
private readonly configProvider: ConfigProvider,
) {
super(browser, storage, requestor);
constructor(private config: ConfigProvider) {
super(new DefaultBrowser(), new LocalStorageBackend(), new JQueryRequestor());
}
async beforeAppInit() {
this.authConfig = getClientConfig('default', this.config.auth);
this.localConfiguration = new AuthorizationServiceConfiguration(
getEndpointsConfig('default', this.config.auth),
);
await super.init();
}
get configuration(): Promise<AuthorizationServiceConfiguration> {
@@ -60,22 +61,6 @@ export class DefaultAuthService extends AuthService {
return Promise.resolve(this.localConfiguration);
}
public async init() {
this.setupConfiguration();
this.setupAuthorizationNotifier();
await this.loadTokenFromStorage();
}
setupConfiguration() {
const authConfig = this.configProvider.getAnyValue('auth') as {
default: SCAuthorizationProvider;
};
this.authConfig = getClientConfig('default', authConfig);
this.localConfiguration = new AuthorizationServiceConfiguration(
getEndpointsConfig('default', authConfig),
);
}
public async signOut() {
await this.revokeTokens().catch(error => {
this.notifyActionListers(AuthActionBuilder.SignOutFailed(error));

View File

@@ -12,7 +12,6 @@
* 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 {
AuthorizationError,
AuthorizationRequest,
@@ -47,10 +46,10 @@ import {PAIAAuthorizationResponse} from './paia-authorization-response';
import {PAIAAuthorizationNotifier} from './paia-authorization-notifier';
import {PAIATokenResponse} from './paia-token-response';
import {IPAIAAuthAction, PAIAAuthActionBuilder} from './paia-auth-action';
import {SCAuthorizationProvider} from '@openstapps/core';
import {ConfigProvider} from '../../config/config.provider';
import {getClientConfig, getEndpointsConfig} from '../auth.provider.methods';
import {Injectable} from '@angular/core';
import {ConfigProvider} from '../../config/config.provider';
import {BeforeAppInit} from '../../../before-app-init';
const TOKEN_RESPONSE_KEY = 'paia_token_response';
const AUTH_EXPIRY_BUFFER = 10 * 60 * -1; // 10 minutes in seconds
@@ -64,10 +63,8 @@ export interface IAuthService {
getValidToken(buffer?: number): Promise<PAIATokenResponse>;
}
@Injectable({
providedIn: 'root',
})
export class PAIAAuthService {
@Injectable({providedIn: 'root'})
export class PAIAAuthService implements BeforeAppInit {
private _authConfig?: IAuthConfig;
private _authSubject: AuthSubject = new AuthSubject();
@@ -97,7 +94,7 @@ export class PAIAAuthService {
protected browser: Browser = new DefaultBrowser(),
protected storage: StorageBackend = new LocalStorageBackend(),
protected requestor: Requestor = new JQueryRequestor(),
private readonly configProvider: ConfigProvider,
private config: ConfigProvider,
) {
this.tokenHandler = new PAIATokenRequestHandler(requestor);
this.userInfoHandler = new IonicUserInfoHandler(requestor);
@@ -110,6 +107,16 @@ export class PAIAAuthService {
this.endSessionHandler = new IonicEndSessionHandler(browser);
}
async beforeAppInit() {
this.authConfig = getClientConfig('paia', this.config.auth);
this.localConfiguration = new AuthorizationServiceConfiguration(
getEndpointsConfig('paia', this.config.auth),
);
this.setupAuthorizationNotifier();
await this.loadTokenFromStorage();
}
get token$(): Observable<PAIATokenResponse | undefined> {
return this._tokenSubject.asObservable();
}
@@ -147,20 +154,6 @@ export class PAIAAuthService {
return Promise.resolve(this.localConfiguration);
}
public async init() {
this.setupConfiguration();
this.setupAuthorizationNotifier();
await this.loadTokenFromStorage();
}
setupConfiguration() {
const authConfig = this.configProvider.getAnyValue('auth') as {
paia: SCAuthorizationProvider;
};
this.authConfig = getClientConfig('paia', authConfig);
this.localConfiguration = new AuthorizationServiceConfiguration(getEndpointsConfig('paia', authConfig));
}
protected notifyActionListers(action: IPAIAAuthAction) {
/* eslint-disable unicorn/no-useless-undefined */
switch (action.action) {

View File

@@ -12,7 +12,6 @@
* 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 {Calendar} from '@awesome-cordova-plugins/calendar/ngx';
import {Injectable} from '@angular/core';
import {ICalEvent} from './ical/ical';
@@ -29,18 +28,18 @@ const RECURRENCE_PATTERNS: Partial<Record<unitOfTime.Diff, string | undefined>>
day: 'daily',
};
@Injectable()
@Injectable({providedIn: 'root'})
export class CalendarService {
goToDate = new Subject<number>();
goToDateClicked = this.goToDate.asObservable();
calendarName = 'StApps';
get calendarName(): string {
return this.config.app.name ?? 'StApps';
}
// eslint-disable-next-line @typescript-eslint/no-empty-function
constructor(readonly calendar: Calendar, private readonly configProvider: ConfigProvider) {
this.calendarName = (this.configProvider.getValue('name') as string) ?? 'StApps';
}
constructor(readonly calendar: Calendar, readonly config: ConfigProvider) {}
async createCalendar(): Promise<CalendarInfo | undefined> {
await this.calendar.createCalendar({

View File

@@ -65,7 +65,7 @@ export class CatalogComponent implements OnInit {
.itemSelectListener()
.pipe(takeUntilDestroyed())
.subscribe(item => {
void this.router.navigate(['data-detail', item.uid]);
void this.router.navigate(['data-detail', item.uid], {state: {item}});
});
}

View File

@@ -1,27 +0,0 @@
/*
* Copyright (C) 2019 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 {DataModule} from '../data/data.module';
import {StorageModule} from '../storage/storage.module';
import {ConfigProvider} from './config.provider';
/**
* TODO
*/
@NgModule({
imports: [StorageModule, DataModule],
providers: [ConfigProvider],
})
export class ConfigModule {}

View File

@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/ban-types */
/*
* Copyright (C) 2022 StApps
* This program is free software: you can redistribute it and/or modify it
@@ -14,19 +15,17 @@
*/
import {Injectable} from '@angular/core';
import {Client} from '@openstapps/api';
import {SCAppConfiguration, SCIndexResponse} from '@openstapps/core';
import packageInfo from '@openstapps/core/package.json';
import {NGXLogger} from 'ngx-logger';
import {environment} from '../../../environments/environment';
import {StAppsWebHttpClient} from '../data/stapps-web-http-client.provider';
import {StorageProvider} from '../storage/storage.provider';
import {
ConfigFetchError,
ConfigInitError,
ConfigValueNotAvailable,
SavedConfigNotAvailable,
WrongConfigVersionInStorage,
} from './errors';
SCAppConfiguration,
SCAuthorizationProvider,
SCBackendConfiguration,
SCIndexResponse,
} from '@openstapps/core';
import coreInfo from '@openstapps/core/package.json';
import {environment} from '../../../environments/environment';
import {StorageProvider} from '../storage/storage.provider';
import {BeforeAppInit} from '../../before-app-init';
import {StAppsWebHttpClient} from '../data/stapps-web-http-client.provider';
/**
* Key to store config in storage module
@@ -35,145 +34,55 @@ import {
*/
export const STORAGE_KEY_CONFIG = 'stapps.config';
/**
* Provides configuration
*/
@Injectable({
providedIn: 'root',
})
export class ConfigProvider {
/**
* Api client
*/
client: Client;
export class ConfigProvider implements SCIndexResponse, BeforeAppInit {
private client: Client;
/**
* App configuration as IndexResponse
*/
config: SCIndexResponse;
constructor(private storageProvider: StorageProvider, httpClient: StAppsWebHttpClient) {
this.client = new Client(httpClient, environment.backend_url, environment.backend_version);
}
/**
* Version of the @openstapps/core package that app is using
*/
scVersion = packageInfo.version;
async beforeAppInit() {
this.isFirstSession = !(await this.storageProvider.has(STORAGE_KEY_CONFIG));
// Queue config update for next launch; don't block current launch
const configUpdate = this.updateConfig();
console.log('Config update queued');
/**
* First session indicator (config not found in storage)
*/
firstSession = true;
const config = await this.storageProvider
.get<SCIndexResponse>(STORAGE_KEY_CONFIG)
.then(it => it ?? configUpdate);
/**
* Constructor, initialise api client
* @param storageProvider StorageProvider to load persistent configuration
* @param swHttpClient Api client
* @param logger An angular logger
*/
constructor(
private readonly storageProvider: StorageProvider,
swHttpClient: StAppsWebHttpClient,
private readonly logger: NGXLogger,
) {
this.client = new Client(swHttpClient, environment.backend_url, environment.backend_version);
Object.assign(this, config);
console.assert(
this.backend.SCVersion === coreInfo.version,
'Wrong config version in storage.',
'Expected:',
coreInfo.version,
'Actual:',
this.backend.SCVersion,
);
}
/**
* Fetches configuration from backend
* Updates the config from remote
*/
async fetch(): Promise<SCIndexResponse> {
try {
return await this.client.handshake(this.scVersion);
} catch {
throw new ConfigFetchError();
}
}
/**
* Returns the value of an app configuration
* @param attribute requested attribute from app configuration
*/
public getValue(attribute: keyof SCAppConfiguration) {
if (this.config.app[attribute] !== undefined) {
return this.config.app[attribute];
}
throw new ConfigValueNotAvailable(attribute);
}
/**
* Returns a value of the configuration (not only app configuration)
* @param attribute requested attribute from the configuration
*/
public getAnyValue(attribute: keyof SCIndexResponse) {
if (this.config[attribute] !== undefined) {
return this.config[attribute];
}
throw new ConfigValueNotAvailable(attribute);
}
/**
* Initialises the ConfigProvider
* @throws ConfigInitError if no configuration could be loaded.
* @throws WrongConfigVersionInStorage if fetch failed and saved config has wrong SCVersion
*/
async init(): Promise<void> {
let loadError;
let fetchError;
// load saved configuration
try {
this.config = await this.loadLocal();
this.firstSession = false;
this.logger.log(`initialised configuration from storage`);
if (this.config.backend.SCVersion !== this.scVersion) {
loadError = new WrongConfigVersionInStorage(this.scVersion, this.config.backend.SCVersion);
}
} catch (error) {
loadError = error;
}
// fetch remote configuration from backend
try {
const fetchedConfig: SCIndexResponse = await this.fetch();
await this.set(fetchedConfig);
this.logger.log(`initialised configuration from remote`);
} catch (error) {
fetchError = error;
}
// check for occurred errors and throw them
if (loadError !== undefined && fetchError !== undefined) {
throw new ConfigInitError();
}
if (loadError !== undefined) {
this.logger.warn(loadError);
}
if (fetchError !== undefined) {
this.logger.warn(fetchError);
}
}
/**
* Returns saved configuration from StorageModule
* @throws SavedConfigNotAvailable if no configuration could be loaded
*/
async loadLocal(): Promise<SCIndexResponse> {
// get local configuration
if (await this.storageProvider.has(STORAGE_KEY_CONFIG)) {
return this.storageProvider.get<SCIndexResponse>(STORAGE_KEY_CONFIG);
}
throw new SavedConfigNotAvailable();
}
/**
* Saves the configuration from the provider
* @param config configuration to save
*/
async save(config: SCIndexResponse): Promise<void> {
async updateConfig(): Promise<SCIndexResponse> {
const config = await this.client.handshake(coreInfo.version);
await this.storageProvider.put(STORAGE_KEY_CONFIG, config);
console.log(`Config updated`);
return config;
}
/**
* Sets the configuration in the module and writes it into app storage
* @param config SCIndexResponse to set
*/
async set(config: SCIndexResponse): Promise<void> {
this.config = config;
await this.save(this.config);
}
app: SCAppConfiguration;
auth: {default?: SCAuthorizationProvider | undefined; paia?: SCAuthorizationProvider | undefined};
backend: SCBackendConfiguration;
isFirstSession: boolean;
}

View File

@@ -1,65 +0,0 @@
/*
* Copyright (C) 2022 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 {AppError} from '../../_helpers/errors';
/**
* Error that is thrown when fetching from backend fails
*/
export class ConfigFetchError extends AppError {
constructor() {
super('ConfigFetchError', 'App configuration could not be fetched!');
}
}
/**
* Error that is thrown when the ConfigProvider could be initialised
*/
export class ConfigInitError extends AppError {
constructor() {
super('ConfigInitError', 'App configuration could not be initialised!');
}
}
/**
* Error that is thrown when the requested config value is not available
*/
export class ConfigValueNotAvailable extends AppError {
constructor(valueKey: string) {
super('ConfigValueNotAvailable', `No attribute "${valueKey}" in config available!`);
}
}
/**
* Error that is thrown when no saved config is available
*/
export class SavedConfigNotAvailable extends AppError {
constructor() {
super('SavedConfigNotAvailable', 'No saved app configuration available.');
}
}
/**
* Error that is thrown when the SCVersion of the saved config is not compatible with the app
*/
export class WrongConfigVersionInStorage extends AppError {
constructor(correctVersion: string, savedVersion: string) {
super(
'WrongConfigVersionInStorage',
`The saved configs backend version ${savedVersion} ` +
`does not equal the configured backend version ${correctVersion} of the app.`,
);
}
}

View File

@@ -26,6 +26,7 @@
<!-- Avoid structural directives here, they might interfere with the collapse animation -->
<a
[routerLink]="nextEvent ? ['/data-detail', nextEvent!.uid] : ['/schedule/calendar']"
[state]="{item: nextEvent}"
class="schedule-item-button"
>
<ion-label>{{ 'dashboard.schedule.title' | translate }}</ion-label>

View File

@@ -76,7 +76,7 @@ export class DashboardComponent implements OnInit, OnDestroy {
.itemSelectListener()
.pipe(takeUntilDestroyed())
.subscribe(item => {
void this.router.navigate(['data-detail', item.uid]);
void this.router.navigate(['data-detail', item.uid], {state: {item}});
});
}

View File

@@ -18,7 +18,6 @@
<stapps-data-list-item
*ngFor="let dish of dishes"
[hideThumbnail]="true"
[favoriteButton]="false"
[item]="dish"
appearance="square"
></stapps-data-list-item>

View File

@@ -42,6 +42,7 @@ export class ActionChipListComponent {
event:
item.type === SCThingType.AcademicEvent ||
(item.type === SCThingType.DateSeries && (item as SCDateSeries).dates.length > 0),
navigate: ('inPlace' in item && item.inPlace && 'geo' in item.inPlace) || 'geo' in item,
};
}

View File

@@ -14,5 +14,6 @@
-->
<stapps-locate-action-chip *ngIf="applicable.locate" [item]="item"></stapps-locate-action-chip>
<stapps-navigate-action-chip *ngIf="applicable.navigate" [item]="$any(item)"></stapps-navigate-action-chip>
<!-- Add Event Chip needs to load data and should be the last -->
<stapps-add-event-action-chip *ngIf="applicable.event" [item]="item"></stapps-add-event-action-chip>

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 StApps
* Copyright (C) 2023 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.
@@ -13,19 +13,23 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {Component, Input} from '@angular/core';
import {SCPlace} from '@openstapps/core';
import {ModalController} from '@ionic/angular';
import {SCPlaceWithoutReferences, SCThings} from '@openstapps/core';
@Component({
selector: 'app-map-single-modal',
templateUrl: './map-single.html',
styleUrls: ['./map-single.scss'],
selector: 'stapps-navigate-action-chip',
templateUrl: 'navigate-action-chip.html',
styleUrls: ['navigate-action-chip.scss'],
})
export class MapSingleModalComponent {
/**
* The item to be shown
*/
@Input() item: SCPlace;
export class NavigateActionChipComponent {
place: SCPlaceWithoutReferences;
constructor(readonly modalController: ModalController) {}
@Input({required: true}) set item(value: SCThings) {
if ('geo' in value) {
this.place = value;
} else if ('inPlace' in value && value.inPlace && 'geo' in value.inPlace) {
this.place = value.inPlace;
} else {
console.error('Invalid place', value);
}
}
}

View File

@@ -1,5 +1,5 @@
<!--
~ Copyright (C) 2022 StApps
~ Copyright (C) 2023 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.
@@ -12,15 +12,7 @@
~ You should have received a copy of the GNU General Public License along with
~ this program. If not, see <https://www.gnu.org/licenses/>.
-->
<ion-header translucent>
<ion-toolbar color="primary" mode="ios">
<ion-title>{{ 'map.modals.single.TITLE' | translate }}</ion-title>
<ion-buttons slot="end">
<ion-button (click)="modalController.dismiss()">{{ 'app.ui.CLOSE' | translate }}</ion-button>
</ion-buttons>
</ion-toolbar>
</ion-header>
<ion-content>
<stapps-data-detail-content [item]="$any(item)" [openAsModal]="true"></stapps-data-detail-content>
</ion-content>
<ion-chip [color]="'primary'" [outline]="true" [geoNavigation]="place">
<ion-icon name="directions"></ion-icon>
<ion-label>{{'map.directions.TITLE' | translate}}</ion-label>
</ion-chip>

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 StApps
/*!
* Copyright (C) 2023 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.
@@ -12,8 +12,3 @@
* 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 {NGXLogger} from 'ngx-logger';
export let logger: NGXLogger;
export const initLogger = (newLogger: NGXLogger) => (logger = newLogger);

View File

@@ -102,6 +102,8 @@ import {StappsRatingComponent} from './elements/rating.component';
import {DishCharacteristicsComponent} from './types/dish/dish-characteristics.component';
import {SkeletonListComponent} from './list/skeleton-list.component';
import {CertificationsInDetailComponent} from './elements/certifications-in-detail.component';
import {GeoNavigationDirective} from '../map/geo-navigation.directive';
import {NavigateActionChipComponent} from './chips/data/navigate-action-chip.component';
/**
* Module for handling data
@@ -110,6 +112,7 @@ import {CertificationsInDetailComponent} from './elements/certifications-in-deta
declarations: [
ActionChipListComponent,
AddEventActionChipComponent,
NavigateActionChipComponent,
EditEventSelectionComponent,
AddressDetailComponent,
CatalogDetailContentComponent,
@@ -194,6 +197,7 @@ import {CertificationsInDetailComponent} from './elements/certifications-in-deta
TranslateModule.forChild(),
ThingTranslateModule.forChild(),
UtilModule,
GeoNavigationDirective,
],
providers: [
CoordinatedSearchProvider,

View File

@@ -111,8 +111,8 @@ describe('DataDetailComponent', () => {
expect(DataDetailComponent.prototype.getItem).toHaveBeenCalledWith(sampleThing.uid, false);
});
it('should get a data item when the view is entered', () => {
comp.ionViewWillEnter();
it('should get a data item when initialized', () => {
comp.ngOnInit();
expect(DataDetailComponent.prototype.getItem).toHaveBeenCalledWith(sampleThing.uid, false);
});
});

View File

@@ -12,9 +12,9 @@
* 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 {Component, ContentChild, EventEmitter, Input, Output, TemplateRef} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {ModalController, ViewWillEnter} from '@ionic/angular';
import {Component, ContentChild, EventEmitter, Input, OnInit, Output, TemplateRef} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {ModalController} from '@ionic/angular';
import {LangChangeEvent, TranslateService} from '@ngx-translate/core';
import {SCLanguageCode, SCSaveableThing, SCThings, SCUuid} from '@openstapps/core';
import {DataProvider, DataScope} from '../data.provider';
@@ -37,7 +37,7 @@ export interface ExternalDataLoadEvent {
styleUrls: ['data-detail.scss'],
templateUrl: 'data-detail.html',
})
export class DataDetailComponent implements ViewWillEnter {
export class DataDetailComponent implements OnInit {
/**
* The associated item
*
@@ -84,21 +84,15 @@ export class DataDetailComponent implements ViewWillEnter {
return (thing as SCSaveableThing).data !== undefined;
}
/**
*
* @param route the route the page was accessed from
* @param dataProvider the data provider
* @param favoritesService the favorites provider
* @param modalController the modal controller
* @param translateService he translate provider
*/
constructor(
protected readonly route: ActivatedRoute,
router: Router,
private readonly dataProvider: DataProvider,
private readonly favoritesService: FavoritesService,
readonly modalController: ModalController,
translateService: TranslateService,
) {
this.inputItem = router.getCurrentNavigation()?.extras.state?.item;
this.language = translateService.currentLang as SCLanguageCode;
translateService.onLangChange.subscribe((event: LangChangeEvent) => {
this.language = event.lang as SCLanguageCode;
@@ -138,10 +132,7 @@ export class DataDetailComponent implements ViewWillEnter {
}
}
/**
* Initialize
*/
async ionViewWillEnter() {
async ngOnInit() {
const uid = this.route.snapshot.paramMap.get('uid') || '';
await this.getItem(uid ?? '', false);
// fallback to the saved item (from favorites)

View File

@@ -37,32 +37,22 @@ export class DataPathComponent implements OnInit {
@Input() maxItems = 2;
@Input() set item(item: SCThings) {
// eslint-disable-next-line unicorn/prefer-ternary
if (item.type === SCThingType.Catalog && item.superCatalogs) {
this.path = new Promise(resolve =>
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
resolve([...item.superCatalogs!, item]),
);
this.path = Promise.resolve([...item.superCatalogs!, item]);
} else if (item.type === SCThingType.Assessment && item.superAssessments) {
this.path = new Promise(resolve =>
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
resolve([...item.superAssessments!, item]),
);
this.path = Promise.resolve([...item.superAssessments!, item]);
} else if (
item.type === SCThingType.AcademicEvent &&
item.catalogs &&
(item.catalogs.length === 1 || this.routeStack.lastDataDetail)
) {
const catalogWithoutReferences = item.catalogs[0];
const catalogPromise = (
item.catalogs.length === 1
? this.dataProvider.get(catalogWithoutReferences.uid, DataScope.Remote)
: this.routeStack.lastDataDetail
) as Promise<SCCatalog>;
this.path = new Promise(async resolve => {
const catalog = await catalogPromise;
const superCatalogs = catalog.superCatalogs;
const catalogWithoutReferences = item.catalogs![0];
const catalog =
item.catalogs!.length === 1
? await this.dataProvider.get(catalogWithoutReferences.uid, DataScope.Remote)
: this.routeStack.lastDataDetail;
const superCatalogs = (catalog as SCCatalog).superCatalogs;
resolve(
superCatalogs

View File

@@ -30,9 +30,8 @@ export class OffersInListComponent {
@Input() set offers(it: Array<SCThingThatCanBeOfferedOffer<SCAcademicPriceGroup>>) {
this._offers = it;
this.price = it[0].prices?.default;
this.settingsProvider.getSetting('profile', 'group').then(group => {
this.price = it[0].prices?.[(group.value as string).replace(/s$/, '') as never];
});
const group = this.settingsProvider.getSetting('profile', 'group');
this.price = it[0].prices?.[(group.value as string).replace(/s$/, '') as never];
const availabilities = new Set(it.map(offer => offer.availability));
this.soldOut = availabilities.has('out of stock') && availabilities.size === 1;

View File

@@ -17,7 +17,7 @@ import {MapPosition} from '../../map/position.service';
import {SearchPageComponent} from './search-page.component';
import {Geolocation} from '@capacitor/geolocation';
import {BehaviorSubject} from 'rxjs';
import {pauseWhen} from '../../../util/pause-when';
import {pauseWhen} from '../../../util/rxjs/pause-when';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
/**

View File

@@ -15,16 +15,9 @@
import {Component, DestroyRef, inject, Input, OnInit} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {Keyboard} from '@capacitor/keyboard';
import {AlertController, AnimationBuilder, AnimationController} from '@ionic/angular';
import {AlertController, AnimationController} from '@ionic/angular';
import {Capacitor} from '@capacitor/core';
import {
SCFacet,
SCFeatureConfiguration,
SCSearchFilter,
SCSearchQuery,
SCSearchSort,
SCThings,
} from '@openstapps/core';
import {SCFacet, SCSearchFilter, SCSearchQuery, SCSearchSort, SCThings} from '@openstapps/core';
import {NGXLogger} from 'ngx-logger';
import {combineLatest, Subject} from 'rxjs';
import {debounceTime, distinctUntilChanged, startWith} from 'rxjs/operators';
@@ -33,9 +26,9 @@ import {SettingsProvider} from '../../settings/settings.provider';
import {DataRoutingService} from '../data-routing.service';
import {DataProvider} from '../data.provider';
import {PositionService} from '../../map/position.service';
import {ConfigProvider} from '../../config/config.provider';
import {searchPageSwitchAnimation} from './search-page-switch-animation';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {ConfigProvider} from '../../config/config.provider';
/**
* SearchPageComponent queries things and shows list of things as search results and filter as context menu
@@ -144,21 +137,8 @@ export class SearchPageComponent implements OnInit {
destroy$ = inject(DestroyRef);
routeAnimation: AnimationBuilder;
routeAnimation = searchPageSwitchAnimation(inject(AnimationController));
/**
* Injects the providers and creates subscriptions
* @param alertController AlertController
* @param dataProvider DataProvider
* @param contextMenuService ContextMenuService
* @param settingsProvider SettingsProvider
* @param logger An angular logger
* @param dataRoutingService DataRoutingService
* @param router Router
* @param route ActivatedRoute
* @param positionService PositionService
* @param configProvider ConfigProvider
*/
constructor(
protected readonly alertController: AlertController,
protected dataProvider: DataProvider,
@@ -169,11 +149,8 @@ export class SearchPageComponent implements OnInit {
protected router: Router,
private readonly route: ActivatedRoute,
protected positionService: PositionService,
private readonly configProvider: ConfigProvider,
animationController: AnimationController,
) {
this.routeAnimation = searchPageSwitchAnimation(animationController);
}
private readonly config: ConfigProvider,
) {}
/**
* Fetches items with set query configuration
@@ -342,13 +319,12 @@ export class SearchPageComponent implements OnInit {
.pipe(takeUntilDestroyed(this.destroy$))
.subscribe(item => {
if (this.itemRouting) {
void this.router.navigate(['/data-detail', item.uid]);
void this.router.navigate(['/data-detail', item.uid], {state: {item}});
}
});
}
try {
const features = this.configProvider.getValue('features') as SCFeatureConfiguration;
this.isHebisAvailable = !!features.plugins?.['hebis-plugin']?.urlPath;
this.isHebisAvailable = !!this.config.app.features.plugins?.['hebis-plugin']?.urlPath;
} catch (error) {
this.logger.error(error);
}

View File

@@ -61,7 +61,7 @@ export class SimpleDataListComponent implements OnInit {
.itemSelectListener()
.pipe(takeUntilDestroyed(this.destroy$))
.subscribe(item => {
void this.router.navigate(['/data-detail', item.uid]);
void this.router.navigate(['/data-detail', item.uid], {state: {item}});
});
}
}

View File

@@ -13,16 +13,16 @@
~ this program. If not, see <https://www.gnu.org/licenses/>.
-->
<ng-container *ngIf="items as items; else loading">
<ng-container *ngIf="items | async as items; else loading">
<ion-list>
<ng-container *ngIf="!listHeader; else header"></ng-container>
<ng-container *ngFor="let item of items | async">
<ng-container *ngFor="let item of items">
<ng-container
*ngTemplateOutlet="listItemTemplateRef || defaultListItem; context: {$implicit: item}"
></ng-container>
</ng-container>
</ion-list>
<ion-label class="empty-list-message" *ngIf="emptyListMessage && (items | async)?.length === 0"
<ion-label class="empty-list-message" *ngIf="emptyListMessage && items.length === 0"
>{{ emptyListMessage }}</ion-label
>
</ng-container>

View File

@@ -62,10 +62,8 @@ export class RatingProvider {
return new Date(today.getFullYear(), today.getMonth(), today.getDate()).toISOString();
}
private get userGroup(): Promise<SCUserGroup> {
return this.settingsProvider
.getSetting('profile', 'group')
.then(it => (it as SCUserGroupSetting).value as SCUserGroup);
private get userGroup(): SCUserGroup {
return (this.settingsProvider.getSetting('profile', 'group') as SCUserGroupSetting).value as SCUserGroup;
}
private async getStoredRatings(): Promise<RatingStorage> {

View File

@@ -13,94 +13,93 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {Component, Input, OnInit} from '@angular/core';
import {SCCatalog, SCSearchBooleanFilter, SCDucetSort} from '@openstapps/core';
import {SearchPageComponent} from '../../list/search-page.component';
import {SCCatalog, SCThings} from '@openstapps/core';
import {DataProvider} from '../../data.provider';
@Component({
selector: 'stapps-catalog-detail-content',
templateUrl: 'catalog-detail-content.html',
styleUrls: ['catalog-detail-content.scss'],
})
export class CatalogDetailContentComponent extends SearchPageComponent implements OnInit {
export class CatalogDetailContentComponent implements OnInit {
/**
* SCCatalog to display
*/
@Input() item: SCCatalog;
ngOnInit() {
super.ngOnInit();
}
items: Promise<SCThings[]>;
initialize() {
this.showDefaultData = true;
this.pageSize = 100;
constructor(private dataProvider: DataProvider) {}
const nameSort: SCDucetSort = {
arguments: {field: 'name'},
order: 'asc',
type: 'ducet',
};
const typeSort: SCDucetSort = {
arguments: {field: 'type'},
order: 'desc',
type: 'ducet',
};
this.sortQuery = [typeSort, nameSort];
const subCatalogFilter: SCSearchBooleanFilter = {
arguments: {
operation: 'and',
filters: [
async ngOnInit() {
this.items = this.dataProvider
.search({
size: 100,
sort: [
{
type: 'value',
arguments: {
field: 'type',
value: 'catalog',
},
arguments: {field: 'type'},
order: 'desc',
type: 'ducet',
},
{
type: 'value',
arguments: {
field: 'superCatalog.uid',
value: this.item.uid,
},
arguments: {field: 'name'},
order: 'asc',
type: 'ducet',
},
],
},
type: 'boolean',
};
const subEventsFilter: SCSearchBooleanFilter = {
arguments: {
operation: 'and',
filters: [
{
type: 'value',
arguments: {
field: 'type',
value: 'academic event',
},
filter: {
arguments: {
filters: [
{
arguments: {
operation: 'and',
filters: [
{
type: 'value',
arguments: {
field: 'type',
value: 'catalog',
},
},
{
type: 'value',
arguments: {
field: 'superCatalog.uid',
value: this.item.uid,
},
},
],
},
type: 'boolean',
},
{
arguments: {
operation: 'and',
filters: [
{
type: 'value',
arguments: {
field: 'type',
value: 'academic event',
},
},
{
type: 'value',
arguments: {
field: 'catalogs.uid',
value: this.item.uid,
},
},
],
},
type: 'boolean',
},
],
operation: 'or',
},
{
type: 'value',
arguments: {
field: 'catalogs.uid',
value: this.item.uid,
},
},
],
},
type: 'boolean',
};
this.forcedFilter = {
arguments: {
filters: [subCatalogFilter, subEventsFilter],
operation: 'or',
},
type: 'boolean',
};
type: 'boolean',
},
})
.then(({data}) => data);
}
}

View File

@@ -40,7 +40,7 @@ export class DateSeriesDetailContentComponent implements OnInit {
.itemSelectListener()
.pipe(takeUntilDestroyed())
.subscribe(item => {
void router.navigate(['/data-detail', item.uid]);
void router.navigate(['/data-detail', item.uid], {state: {item}});
});
}

View File

@@ -63,3 +63,4 @@
<stapps-data-list-item [item]="$any(item.inPlace)"></stapps-data-list-item>
</ion-card-content>
</ion-card>
<stapps-map-widget *ngIf="item.inPlace?.geo" [place]="item.inPlace"></stapps-map-widget>

View File

@@ -59,7 +59,7 @@ export class PlaceDetailContentComponent implements OnInit {
.itemSelectListener()
.pipe(takeUntilDestroyed())
.subscribe(item => {
void router.navigate(['/data-detail', item.uid]);
void router.navigate(['/data-detail', item.uid], {state: {item}});
});
}

View File

@@ -38,9 +38,5 @@
</ion-card>
</ng-container>
<ng-container *ngIf="hasValidLocation">
<stapps-map-widget
class="map-widget expand-when-space"
[place]="item"
expandable="true"
></stapps-map-widget>
<stapps-map-widget [place]="item" expandable="true"></stapps-map-widget>
</ng-container>

View File

@@ -12,10 +12,3 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
.map-widget {
position: relative;
width: auto;
height: 300px;
min-height: 300px;
}

View File

@@ -12,10 +12,11 @@
* 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 {Component, Input} from '@angular/core';
import {ChangeDetectionStrategy, Component, Input} from '@angular/core';
import {PositionService} from '../../../map/position.service';
import {interval, Subscription} from 'rxjs';
import {Observable, timer} from 'rxjs';
import {hasValidLocation, isSCFloor, PlaceTypes, PlaceTypesWithDistance} from './place-types';
import {map} from 'rxjs/operators';
/**
* Shows a place as a list item
@@ -24,14 +25,10 @@ import {hasValidLocation, isSCFloor, PlaceTypes, PlaceTypesWithDistance} from '.
selector: 'stapps-place-list-item',
templateUrl: 'place-list-item.html',
styleUrls: ['place-list-item.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class PlaceListItemComponent {
/**
* Item getter
*/
get item(): PlaceTypesWithDistance {
return this._item;
}
_item: PlaceTypesWithDistance;
/**
* An item to show (setter is used as there were issues assigning the distance to the right place in a list)
@@ -39,24 +36,14 @@ export class PlaceListItemComponent {
@Input() set item(item: PlaceTypes) {
this._item = item;
if (!isSCFloor(item) && hasValidLocation(item)) {
this.distance = this.positionService.getDistance(item.geo.point);
this.distanceSubscription = interval(10_000).subscribe(_ => {
this.distance = this.positionService.getDistance(item.geo.point);
});
this.distance = timer(0, 10_000).pipe(map(() => this.positionService.getDistance(item.geo.point)));
}
}
/**
* An item to show
*/
private _item: PlaceTypesWithDistance;
/**
* Distance in meters
*/
distance?: number;
distanceSubscription?: Subscription;
distance?: Observable<number | undefined>;
constructor(private positionService: PositionService) {}
}

View File

@@ -17,17 +17,17 @@
<ion-row>
<ion-col>
<div class="ion-text-wrap">
<ion-label class="title">{{ 'name' | thingTranslate: item }}</ion-label>
<ng-container *ngIf="item.type !== 'floor'">
<p class="title-sub" *ngIf="item.openingHours">
<ion-label class="title">{{ 'name' | thingTranslate: _item }}</ion-label>
<ng-container *ngIf="_item.type !== 'floor'">
<p class="title-sub" *ngIf="_item.openingHours">
<span>
<stapps-opening-hours [openingHours]="item.openingHours"></stapps-opening-hours>
<stapps-opening-hours [openingHours]="_item.openingHours"></stapps-opening-hours>
</span>
</p>
<p>
<ion-note *ngIf="item.categories && item.type !== 'building'; else onlyType">
<ion-label> {{ 'categories' | thingTranslate: item | join: ', ' | titlecase }} </ion-label>
<ion-label *ngIf="distance" class="distance">
<ion-note *ngIf="_item.categories && _item.type !== 'building'; else onlyType">
<ion-label> {{ 'categories' | thingTranslate: _item | join: ', ' | titlecase }} </ion-label>
<ion-label *ngIf="distance | async as distance" class="distance">
<ion-icon name="directions_walk"></ion-icon>
{{ distance | metersLocalized }}
</ion-label>
@@ -35,21 +35,21 @@
</p>
<ng-template #onlyType>
<ion-note>
<ion-label> {{ 'type' | thingTranslate: item | titlecase }} </ion-label>
<ion-label *ngIf="distance" class="distance">
<ion-label> {{ 'type' | thingTranslate: _item | titlecase }} </ion-label>
<ion-label *ngIf="distance | async as distance" class="distance">
<ion-icon name="directions_walk"></ion-icon>
{{ distance | metersLocalized }}
</ion-label>
</ion-note>
</ng-template>
</ng-container>
<p *ngIf="item.description">{{ 'description' | thingTranslate: item }}</p>
<p *ngIf="_item.description">{{ 'description' | thingTranslate: _item }}</p>
</div>
</ion-col>
<ng-container *ngIf="item.type !== 'building'">
<ion-col size="auto" class="in-place" *ngIf="item.inPlace">
<ng-container *ngIf="_item.type !== 'building'">
<ion-col size="auto" class="in-place" *ngIf="_item.inPlace">
<ion-icon name="pin_drop"></ion-icon
><ion-label>{{ 'name' | thingTranslate: item.inPlace }}</ion-label>
><ion-label>{{ 'name' | thingTranslate: _item.inPlace }}</ion-label>
</ion-col>
</ng-container>
</ion-row>

View File

@@ -75,7 +75,7 @@ export class PlaceMensaDetailComponent implements AfterViewInit {
.itemSelectListener()
.pipe(takeUntilDestroyed(this.destroy$))
.subscribe(item => {
void this.router.navigate(['/data-detail', item.uid]);
void this.router.navigate(['/data-detail', item.uid], {state: {item}});
});
}

View File

@@ -12,21 +12,13 @@
* 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 {Component, OnInit} from '@angular/core';
import {AlertController, AnimationController} from '@ionic/angular';
import {ActivatedRoute, Router} from '@angular/router';
import {NGXLogger} from 'ngx-logger';
import {Component, inject, OnInit} from '@angular/core';
import {debounceTime, distinctUntilChanged, startWith, take} from 'rxjs/operators';
import {combineLatest} from 'rxjs';
import {SCThingType} from '@openstapps/core';
import {FavoritesService} from './favorites.service';
import {DataRoutingService} from '../data/data-routing.service';
import {ContextMenuService} from '../menu/context/context-menu.service';
import {SearchPageComponent} from '../data/list/search-page.component';
import {DataProvider} from '../data/data.provider';
import {SettingsProvider} from '../settings/settings.provider';
import {PositionService} from '../map/position.service';
import {ConfigProvider} from '../config/config.provider';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
/**
@@ -42,34 +34,7 @@ export class FavoritesPageComponent extends SearchPageComponent implements OnIni
showNavigation = false;
constructor(
alertController: AlertController,
dataProvider: DataProvider,
contextMenuService: ContextMenuService,
settingsProvider: SettingsProvider,
logger: NGXLogger,
dataRoutingService: DataRoutingService,
router: Router,
route: ActivatedRoute,
positionService: PositionService,
private favoritesService: FavoritesService,
configProvider: ConfigProvider,
animationController: AnimationController,
) {
super(
alertController,
dataProvider,
contextMenuService,
settingsProvider,
logger,
dataRoutingService,
router,
route,
positionService,
configProvider,
animationController,
);
}
favoritesService = inject(FavoritesService);
ngOnInit() {
super.ngOnInit(false);
@@ -112,12 +77,15 @@ export class FavoritesPageComponent extends SearchPageComponent implements OnIni
.subscribe(item => {
if (this.itemRouting) {
if ([SCThingType.Book, SCThingType.Periodical, SCThingType.Article].includes(item.type)) {
void this.router.navigate([
'hebis-detail',
(item.origin && 'originalId' in item.origin && item.origin['originalId']) || '',
]);
void this.router.navigate(
[
'hebis-detail',
(item.origin && 'originalId' in item.origin && item.origin['originalId']) || '',
],
{state: {item}},
);
} else {
void this.router.navigate(['data-detail', item.uid]);
void this.router.navigate(['data-detail', item.uid], {state: {item}});
}
}
});

View File

@@ -12,16 +12,11 @@
* 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 {Component, OnInit} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {TranslateService} from '@ngx-translate/core';
import {Component, inject, OnInit} from '@angular/core';
import {SCUuid} from '@openstapps/core';
import {FavoritesService} from '../../favorites/favorites.service';
import {DataProvider} from '../../data/data.provider';
import {DataDetailComponent} from '../../data/detail/data-detail.component';
import {DaiaDataProvider} from '../daia-data.provider';
import {DaiaHolding} from '../protocol/response';
import {ModalController} from '@ionic/angular';
import {groupByStable} from '@openstapps/collection-utils';
/**
@@ -37,28 +32,10 @@ export class DaiaAvailabilityComponent extends DataDetailComponent implements On
holdingsByDepartments?: Map<DaiaHolding['department']['id'], DaiaHolding[]>;
/**
*
* @param route the route the page was accessed from
* @param dataProvider the data provider
* @param favoritesService the favorites provider
* @param modalController the modal controller
* @param translateService he translate provider
* @param daiaDataProvider DaiaDataProvider
*/
constructor(
route: ActivatedRoute,
dataProvider: DataProvider,
favoritesService: FavoritesService,
modalController: ModalController,
translateService: TranslateService,
private daiaDataProvider: DaiaDataProvider,
) {
super(route, dataProvider, favoritesService, modalController, translateService);
}
private daiaDataProvider = inject(DaiaDataProvider);
/**
* Initialize
* @override
*/
async ngOnInit() {
const uid = this.route.snapshot.paramMap.get('uid');

View File

@@ -16,10 +16,9 @@ import {Injectable} from '@angular/core';
import {DaiaAvailabilityResponse, DaiaHolding, DaiaService} from './protocol/response';
import {StorageProvider} from '../storage/storage.provider';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {ConfigProvider} from '../config/config.provider';
import {SCFeatureConfiguration} from '@openstapps/core';
import {NGXLogger} from 'ngx-logger';
import {TranslateService} from '@ngx-translate/core';
import {ConfigProvider} from '../config/config.provider';
/**
* Generated class for the DataProvider provider.
@@ -44,18 +43,10 @@ export class DaiaDataProvider {
clientHeaders = new HttpHeaders();
/**
* TODO
* @param storageProvider TODO
* @param httpClient TODO
* @param configProvider TODO
* @param logger TODO
* @param translateService TODO
*/
constructor(
storageProvider: StorageProvider,
httpClient: HttpClient,
private configProvider: ConfigProvider,
private config: ConfigProvider,
private readonly logger: NGXLogger,
private translateService: TranslateService,
) {
@@ -67,15 +58,14 @@ export class DaiaDataProvider {
async getAvailability(id: string): Promise<DaiaHolding[] | undefined> {
if (this.daiaServiceUrl === undefined) {
try {
const features = this.configProvider.getValue('features') as SCFeatureConfiguration;
if (features.extern?.daia?.url) {
this.daiaServiceUrl = features.extern?.daia?.url;
if (this.config.app.features.extern?.daia?.url) {
this.daiaServiceUrl = this.config.app.features.extern?.daia?.url;
} else {
this.logger.error('Daia service url undefined');
return undefined;
}
if (features.extern?.hebisProxy?.url) {
this.hebisProxyUrl = features.extern?.hebisProxy?.url;
if (this.config.app.features.extern?.hebisProxy?.url) {
this.hebisProxyUrl = this.config.app.features.extern?.hebisProxy?.url;
} else {
this.logger.error('HeBIS proxy url undefined');
return undefined;

View File

@@ -107,8 +107,8 @@ describe('HebisDetailComponent', () => {
expect(HebisDetailComponent.prototype.getItem).toHaveBeenCalledWith(sampleThing.uid, false);
});
it('should get a data item when the view is entered', () => {
comp.ionViewWillEnter();
it('should get a data item when initialized', () => {
comp.ngOnInit();
expect(HebisDetailComponent.prototype.getItem).toHaveBeenCalledWith(sampleThing.uid, false);
});
});

View File

@@ -12,16 +12,11 @@
* 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 {Component} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {TranslateService} from '@ngx-translate/core';
import {Component, inject, OnInit} from '@angular/core';
import {SCUuid} from '@openstapps/core';
import {HebisDataProvider} from '../hebis-data.provider';
import {FavoritesService} from '../../favorites/favorites.service';
import {DataProvider} from '../../data/data.provider';
import {DataDetailComponent} from '../../data/detail/data-detail.component';
import {DaiaHolding} from '../protocol/response';
import {ModalController} from '@ionic/angular';
/**
* A Component to display an SCThing detailed
@@ -31,33 +26,15 @@ import {ModalController} from '@ionic/angular';
styleUrls: ['hebis-detail.scss'],
templateUrl: 'hebis-detail.html',
})
export class HebisDetailComponent extends DataDetailComponent {
export class HebisDetailComponent extends DataDetailComponent implements OnInit {
holdings: DaiaHolding[];
/**
*
* @param route the route the page was accessed from
* @param dataProvider the data provider
* @param favoritesService the favorites provider
* @param modalController the modal controller
* @param translateService he translate provider
* @param hebisDataProvider HebisDataProvider
*/
constructor(
route: ActivatedRoute,
dataProvider: DataProvider,
favoritesService: FavoritesService,
modalController: ModalController,
translateService: TranslateService,
private hebisDataProvider: HebisDataProvider,
) {
super(route, dataProvider, favoritesService, modalController, translateService);
}
private hebisDataProvider = inject(HebisDataProvider);
/**
* Initialize
* @override
*/
async ionViewWillEnter() {
async ngOnInit() {
const uid = this.route.snapshot.paramMap.get('uid') || '';
await this.getItem(uid ?? '', false);
}
@@ -68,9 +45,11 @@ export class HebisDetailComponent extends DataDetailComponent {
* @param _forceReload Ignore any cached data
*/
async getItem(uid: SCUuid, _forceReload: boolean) {
this.hebisDataProvider.hebisSearch({query: uid, page: 0}).then(result => {
// eslint-disable-next-line unicorn/no-null
this.item = (result.data && result.data[0]) || null;
});
this.item = await (this.inputItem ??
this.hebisDataProvider.hebisSearch({query: uid, page: 0}).then(
result =>
// eslint-disable-next-line unicorn/no-null
(result.data && result.data[0]) || null,
));
}
}

View File

@@ -13,19 +13,12 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {Component, Input, OnInit} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {AlertController, AnimationController} from '@ionic/angular';
import {NGXLogger} from 'ngx-logger';
import {combineLatest} from 'rxjs';
import {debounceTime, distinctUntilChanged, startWith} from 'rxjs/operators';
import {ContextMenuService} from '../../menu/context/context-menu.service';
import {SettingsProvider} from '../../settings/settings.provider';
import {DataRoutingService} from '../../data/data-routing.service';
import {SearchPageComponent} from '../../data/list/search-page.component';
import {HebisDataProvider} from '../hebis-data.provider';
import {PositionService} from '../../map/position.service';
import {ConfigProvider} from '../../config/config.provider';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {DataProvider} from '../../data/data.provider';
/**
* HebisSearchPageComponent queries things and shows list of things as search results and filter as context menu
@@ -34,6 +27,7 @@ import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
selector: 'stapps-hebissearch-page',
templateUrl: 'hebis-search-page.html',
styleUrls: ['../../data/list/search-page.scss'],
providers: [{provide: DataProvider, useClass: HebisDataProvider}],
})
export class HebisSearchPageComponent extends SearchPageComponent implements OnInit {
/**
@@ -46,47 +40,6 @@ export class HebisSearchPageComponent extends SearchPageComponent implements OnI
*/
page = 0;
/**
* Injects the providers and creates subscriptions
* @param alertController AlertController
* @param dataProvider HebisProvider
* @param contextMenuService ContextMenuService
* @param settingsProvider SettingsProvider
* @param logger An angular logger
* @param dataRoutingService DataRoutingService
* @param router Router
* @param route Active Route
* @param positionService PositionService
* @param configProvider ConfigProvider
*/
constructor(
protected readonly alertController: AlertController,
protected dataProvider: HebisDataProvider,
protected readonly contextMenuService: ContextMenuService,
protected readonly settingsProvider: SettingsProvider,
protected readonly logger: NGXLogger,
protected dataRoutingService: DataRoutingService,
protected router: Router,
route: ActivatedRoute,
protected positionService: PositionService,
configProvider: ConfigProvider,
animationController: AnimationController,
) {
super(
alertController,
dataProvider,
contextMenuService,
settingsProvider,
logger,
dataRoutingService,
router,
route,
positionService,
configProvider,
animationController,
);
}
/**
* Fetches items with set query configuration
* @param append If true fetched data gets appended to existing, override otherwise (default false)
@@ -103,7 +56,7 @@ export class HebisSearchPageComponent extends SearchPageComponent implements OnI
searchOptions.query = this.queryText;
}
return this.dataProvider.hebisSearch(searchOptions).then(
return (this.dataProvider as HebisDataProvider).hebisSearch(searchOptions).then(
async result => {
/*this.singleTypeResponse =
result.facets.find(facet => facet.field === 'type')?.buckets
@@ -176,10 +129,10 @@ export class HebisSearchPageComponent extends SearchPageComponent implements OnI
.pipe(takeUntilDestroyed(this.destroy$))
.subscribe(async item => {
if (this.itemRouting) {
void this.router.navigate([
'hebis-detail',
(item.origin && 'originalId' in item.origin && item.origin['originalId']) || '',
]);
void this.router.navigate(
['hebis-detail', (item.origin && 'originalId' in item.origin && item.origin['originalId']) || ''],
{state: {item}},
);
}
});
}

View File

@@ -12,22 +12,17 @@
* 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} from '@angular/core';
import {JQueryRequestor, Requestor} from '@openid/appauth';
import {
SCAuthorizationProviderType,
SCFeatureConfiguration,
SCFeatureConfigurationExtern,
} from '@openstapps/core';
import {SCAuthorizationProviderType} from '@openstapps/core';
import {DocumentAction, PAIADocument, PAIADocumentStatus, PAIAFees, PAIAItems, PAIAPatron} from '../types';
import {HebisDataProvider} from '../../hebis/hebis-data.provider';
import {PAIATokenResponse} from '../../auth/paia/paia-token-response';
import {AuthHelperService} from '../../auth/auth-helper.service';
import {ConfigProvider} from '../../config/config.provider';
import {TranslateService} from '@ngx-translate/core';
import {AlertController, ToastController} from '@ionic/angular';
import {HebisSearchResponse} from '../../hebis/protocol/response';
import {ConfigProvider} from '../../config/config.provider';
@Injectable({
providedIn: 'root',
@@ -36,29 +31,26 @@ export class LibraryAccountService {
/**
* Base url of the external service
*/
baseUrl: string;
get baseUrl(): string {
return this.config.app.features.extern!['paia'].url;
}
/**
* Authorization provider type
*/
authType: SCAuthorizationProviderType;
get authType(): SCAuthorizationProviderType {
return this.config.app.features.extern!['paia'].authProvider!;
}
constructor(
protected requestor: Requestor = new JQueryRequestor(),
private readonly hebisDataProvider: HebisDataProvider,
private readonly authHelper: AuthHelperService,
readonly configProvider: ConfigProvider,
private readonly translateService: TranslateService,
private readonly alertController: AlertController,
private readonly toastController: ToastController,
) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const config: SCFeatureConfigurationExtern = (
configProvider.getValue('features') as SCFeatureConfiguration
).extern!.paia;
this.baseUrl = config.url;
this.authType = config.authProvider as SCAuthorizationProviderType;
}
private readonly config: ConfigProvider,
) {}
async getProfile() {
const patron = ((await this.getValidToken()) as PAIATokenResponse).patron;

View File

@@ -0,0 +1,92 @@
import {Directive, HostListener, Input} from '@angular/core';
import {SCPlaceWithoutReferences, SCThings, SCThingWithoutReferences} from '@openstapps/core';
import {Device} from '@capacitor/device';
import {ActionSheetController, ActionSheetOptions, ToastController} from '@ionic/angular';
import {TranslateService} from '@ngx-translate/core';
import {ThingTranslateService} from '../../translation/thing-translate.service';
import {Clipboard} from '@capacitor/clipboard';
import {PositionService} from './position.service';
/**
* A button that provides navigation options to the user via an action sheet
* @example
* <ion-button shape="round" [geoNavigation]="place">
* <ion-icon name="directions" slot="start"></ion-icon>
* <ion-label>{{'map.directions.TITLE' | translate}}</ion-label>
* </ion-button>
*/
@Directive({
selector: '[geoNavigation]',
standalone: true,
})
export class GeoNavigationDirective {
@Input({required: true}) geoNavigation: SCThingWithoutReferences &
Pick<SCPlaceWithoutReferences, 'geo' | 'address'>;
constructor(
private actionSheetController: ActionSheetController,
private translateService: TranslateService,
private thingTranslate: ThingTranslateService,
private toastController: ToastController,
private positionService: PositionService,
) {}
@HostListener('click', ['$event'])
async presentActionSheet(event: Event) {
event.stopPropagation();
const {operatingSystem} = await Device.getInfo();
const [lon, lat] = this.geoNavigation.geo.point.coordinates;
const supportedMapProviders =
operatingSystem === 'mac' || operatingSystem === 'ios'
? ['OSM_ROUTING', 'APPLE_MAPS', 'GOOGLE_MAPS']
: ['OSM_ROUTING', 'GOOGLE_MAPS'];
const address = this.geoNavigation.address
? this.translateService.instant(
'map.directions.ADDRESS',
this.thingTranslate.get(this.geoNavigation as SCThings, 'address'),
)
: `${lat}, ${lon}`;
const options: ActionSheetOptions = {
header: this.translateService.instant('map.directions.TITLE_LONG', {
name: this.thingTranslate.get(this.geoNavigation as SCThings, 'name'),
}),
subHeader: address,
buttons: [
{
text: this.translateService.instant('map.directions.COPY_ADDRESS'),
role: 'selected',
handler: async () => {
await Clipboard.write({string: address});
this.toastController
.create({
message: this.translateService.instant('map.directions.ADDRESS_COPIED'),
duration: 500,
})
.then(toast => toast.present());
},
},
...supportedMapProviders.map(provider => ({
text: this.translateService.instant(`map.directions.${provider}.TITLE`),
handler: () => {
const url: string = this.translateService.instant(`map.directions.${provider}.URL`, {
lat,
lon,
posLat: this.positionService.position?.latitude ?? 0,
posLon: this.positionService.position?.longitude ?? 0,
});
window.open(url.replace(/&?\w+=0,0/, ''), '_blank', 'noreferrer');
},
})),
{
text: this.translateService.instant('abort'),
role: 'cancel',
},
],
};
const actionSheet = await this.actionSheetController.create(options);
await actionSheet.present();
}
}

View File

@@ -1,36 +0,0 @@
<!--
~ Copyright (C) 2022 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/>.
-->
<ion-card class="compact">
<ion-card-header>
<stapps-data-list-item [item]="$any(item)" id="show-more"></stapps-data-list-item>
<stapps-skeleton-list-item *ngIf="!item"></stapps-skeleton-list-item>
</ion-card-header>
<ion-card-content>
<ion-note>
<span *ngIf="item.address as address">
<span *ngIf="$any(item).inPlace">{{ $any(item).inPlace.name }},</span>
{{ address.streetAddress }}, {{ address.addressLocality }}
</span>
</ion-note>
<ion-button
size="small"
class="show-more-button"
fill="clear"
[routerLink]="['/data-detail', item.uid]"
>{{ 'map.page.buttons.MORE' | translate }}</ion-button
>
</ion-card-content>
</ion-card>

View File

@@ -1,72 +0,0 @@
/*!
* Copyright (C) 2022 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 '../../../../theme/util/mixins';
:host {
display: block;
max-width: 100%;
ion-card {
overflow: visible;
padding: 0;
ion-card-header {
padding: 0;
border-bottom: var(--border-width-default) solid var(--border-color-default);
stapps-data-list-item {
--ion-margin: 0;
&::ng-deep ion-item {
--padding-start: 0;
--padding-end: 0;
ion-label {
white-space: break-spaces;
}
}
}
.close {
--padding-top: 0;
--padding-bottom: 0;
--padding-start: 0;
--padding-end: 0;
position: absolute;
z-index: 1;
top: -15px;
right: -15px;
ion-icon {
width: 30px;
height: 30px;
}
}
}
ion-card-content {
display: flex;
flex-direction: row;
padding: var(--spacing-md);
.show-more-button {
margin-left: auto;
text-transform: uppercase;
}
}
}
}

View File

@@ -1,41 +0,0 @@
/*
* 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 {Component, EventEmitter, Input, Output} from '@angular/core';
import {SCPlace} from '@openstapps/core';
import {IonRouterOutlet} from '@ionic/angular';
@Component({
selector: 'stapps-map-item',
templateUrl: './map-item.component.html',
styleUrls: ['./map-item.component.scss'],
})
export class MapItemComponent {
/**
* An item to show
*/
@Input() item: SCPlace;
// eslint-disable-next-line @angular-eslint/no-output-on-prefix
@Output() onClose = new EventEmitter<void>();
constructor(readonly routerOutlet: IonRouterOutlet) {}
/**
* Action when edit is clicked
*/
onCloseClick() {
this.onClose.emit();
}
}

View File

@@ -19,9 +19,7 @@ import {LeafletModule} from '@asymmetrik/ngx-leaflet';
import {LeafletMarkerClusterModule} from '@asymmetrik/ngx-leaflet-markercluster';
import {IonicModule} from '@ionic/angular';
import {TranslateModule} from '@ngx-translate/core';
import {Polygon} from 'geojson';
import {ThingTranslateModule} from '../../translation/thing-translate.module';
import {ConfigProvider} from '../config/config.provider';
import {DataFacetsProvider} from '../data/data-facets.provider';
import {DataModule} from '../data/data.module';
import {DataProvider} from '../data/data.provider';
@@ -29,23 +27,11 @@ import {StAppsWebHttpClient} from '../data/stapps-web-http-client.provider';
import {MenuModule} from '../menu/menu.module';
import {MapProvider} from './map.provider';
import {MapPageComponent} from './page/map-page.component';
import {MapListModalComponent} from './page/modals/map-list-modal.component';
import {MapSingleModalComponent} from './page/modals/map-single-modal.component';
import {MapItemComponent} from './item/map-item.component';
import {MapListModalComponent} from './page/map-list-modal.component';
import {NgModule} from '@angular/core';
import {UtilModule} from '../../util/util.module';
import {IonIconModule} from '../../util/ion-icon/ion-icon.module';
/**
* Initializes the default area to show in advance (before components are initialized)
* @param configProvider An instance of the ConfigProvider to read the campus polygon from
* @param mapProvider An instance of the MapProvider to set the default polygon (area to show on the map)
*/
export function initMapConfigFactory(configProvider: ConfigProvider, mapProvider: MapProvider) {
return async () => {
mapProvider.defaultPolygon = (await configProvider.getValue('campusPolygon')) as Polygon;
};
}
import {GeoNavigationDirective} from './geo-navigation.directive';
const mapRoutes: Routes = [
{path: 'map', component: MapPageComponent},
@@ -56,7 +42,7 @@ const mapRoutes: Routes = [
* Module containing map related stuff
*/
@NgModule({
declarations: [MapPageComponent, MapListModalComponent, MapSingleModalComponent, MapItemComponent],
declarations: [MapPageComponent, MapListModalComponent],
exports: [],
imports: [
CommonModule,
@@ -71,6 +57,8 @@ const mapRoutes: Routes = [
FormsModule,
ThingTranslateModule,
UtilModule,
GeoNavigationDirective,
GeoNavigationDirective,
],
providers: [Geolocation, MapProvider, DataProvider, DataFacetsProvider, StAppsWebHttpClient],
})

View File

@@ -21,12 +21,11 @@ import {
SCThingType,
SCUuid,
} from '@openstapps/core';
import {Point, Polygon} from 'geojson';
import {Point} from 'geojson';
import {divIcon, geoJSON, LatLng, Map, marker, Marker} from 'leaflet';
import {DataProvider} from '../data/data.provider';
import {MapPosition, PositionService} from './position.service';
import {hasValidLocation} from '../data/types/place/place-types';
import {ConfigProvider} from '../config/config.provider';
import {SCIcon} from '../../util/ion-icon/icon';
/**
@@ -36,11 +35,6 @@ import {SCIcon} from '../../util/ion-icon/icon';
providedIn: 'root',
})
export class MapProvider {
/**
* Area to show when the map is initialized (shown for the first time)
*/
defaultPolygon: Polygon;
/**
* Provide a point marker for a leaflet map
* @param point Point to get marker for
@@ -111,13 +105,7 @@ export class MapProvider {
clearInterval(interval);
};
constructor(
private dataProvider: DataProvider,
private positionService: PositionService,
private configProvider: ConfigProvider,
) {
this.defaultPolygon = this.configProvider.getValue('campusPolygon') as Polygon;
}
constructor(private dataProvider: DataProvider, private positionService: PositionService) {}
/**
* Provide the specific place by its UID

View File

@@ -14,7 +14,7 @@
*/
import {Component, Input, OnInit} from '@angular/core';
import {SCSearchBooleanFilter, SCPlace, SCSearchFilter} from '@openstapps/core';
import {MapProvider} from '../../map.provider';
import {MapProvider} from '../map.provider';
import {ModalController} from '@ionic/angular';
import {LatLngBounds} from 'leaflet';
@@ -23,8 +23,8 @@ import {LatLngBounds} from 'leaflet';
*/
@Component({
selector: 'map-list-modal',
templateUrl: 'map-list.html',
styleUrls: ['map-list.scss'],
templateUrl: 'map-list-modal.html',
styleUrls: ['map-list-modal.scss'],
})
export class MapListModalComponent implements OnInit {
/**

View File

@@ -27,8 +27,10 @@ import {MapProvider} from '../map.provider';
import {MapPosition, PositionService} from '../position.service';
import {Geolocation, PermissionStatus} from '@capacitor/geolocation';
import {Capacitor} from '@capacitor/core';
import {pauseWhen} from '../../../util/pause-when';
import {pauseWhen} from '../../../util/rxjs/pause-when';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {startViewTransition} from '../../../util/view-transition';
import {ConfigProvider} from '../../config/config.provider';
/**
* The main page of the map
@@ -100,7 +102,17 @@ export class MapPageComponent implements OnInit {
/**
* Options of the leaflet map
*/
options: MapOptions;
options: MapOptions = {
center: geoJSON(inject(ConfigProvider).app.campusPolygon).getBounds().getCenter(),
layers: [
tileLayer('https://osm.server.uni-frankfurt.de/tiles/roads/x={x}&y={y}&z={z}', {
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
maxZoom: this.MAX_ZOOM,
}),
],
zoom: this.DEFAULT_ZOOM,
zoomControl: false,
};
/**
* Position of the user on the map
@@ -134,20 +146,7 @@ export class MapPageComponent implements OnInit {
private dataRoutingService: DataRoutingService,
private positionService: PositionService,
readonly routerOutlet: IonRouterOutlet,
) {
// initialize the options
this.options = {
center: geoJSON(this.mapProvider.defaultPolygon).getBounds().getCenter(),
layers: [
tileLayer('https://osm.server.uni-frankfurt.de/tiles/roads/x={x}&y={y}&z={z}', {
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
maxZoom: this.MAX_ZOOM,
}),
],
zoom: this.DEFAULT_ZOOM,
zoomControl: false,
};
}
) {}
ngOnInit() {
this.dataRoutingService
@@ -158,7 +157,7 @@ export class MapPageComponent implements OnInit {
if (this.items.length > 1) {
await Promise.all([this.modalController.dismiss(), this.showItem(item.uid)]);
} else {
void this.router.navigate(['/data-detail', item.uid]);
void this.router.navigate(['/data-detail', item.uid], {state: {item}});
}
});
this.positionService
@@ -305,6 +304,7 @@ export class MapPageComponent implements OnInit {
*/
async onMapReady(map: Map) {
this.map = map;
this.map.attributionControl.setPosition('topright');
const interval = window.setInterval(() =>
MapProvider.invalidateWhenRendered(map, this.mapContainer, interval),
);
@@ -384,10 +384,12 @@ export class MapPageComponent implements OnInit {
* Resets the map = fetch all the items based on the filters (and go to component's base location)
*/
async resetView() {
this.location.go('/map');
await this.fetchAndUpdateItems(this.items.length > 0);
startViewTransition(async () => {
this.location.go('/map');
await this.fetchAndUpdateItems(this.items.length > 0);
this.ref.detectChanges();
this.ref.detectChanges();
});
}
/**
@@ -414,14 +416,16 @@ export class MapPageComponent implements OnInit {
* @param uid Uuid of the place
*/
async showItem(uid: SCUuid) {
const response = await this.mapProvider.searchPlace(uid);
this.items = response.data as SCPlace[];
this.distance = this.positionService.getDistance(this.items[0].geo.point);
this.addToMap(this.items, true);
this.ref.detectChanges();
const url = this.router.createUrlTree(['/map', uid]).toString();
this.location.go(url);
// center the selected place
this.focus(geoJSON(this.items[0].geo.point).getBounds().getCenter());
startViewTransition(async () => {
const response = await this.mapProvider.searchPlace(uid);
this.items = response.data as SCPlace[];
this.distance = this.positionService.getDistance(this.items[0].geo.point);
this.addToMap(this.items, true);
this.ref.detectChanges();
const url = this.router.createUrlTree(['/map', uid]).toString();
this.location.go(url);
// center the selected place
this.focus(geoJSON(this.items[0].geo.point).getBounds().getCenter());
});
}
}

View File

@@ -43,7 +43,7 @@
</ion-toolbar>
</ion-header>
<ion-content fullscreen id="map">
<ion-content id="map">
<div
class="map-container"
#mapContainer
@@ -57,7 +57,7 @@
<div *ngIf="position" [leafletLayer]="positionMarker"></div>
</div>
<div class="floating-content">
<div class="map-buttons above">
<div class="map-buttons">
<ion-button
*ngIf="items.length > 1"
color="light"
@@ -67,7 +67,13 @@
>
<ion-icon name="list"></ion-icon>&nbsp;&nbsp;{{ 'map.page.buttons.SHOW_LIST' | translate }}
</ion-button>
<ion-button color="light" shape="round" size="small" (click)="onPositionClick()">
<ion-button
color="light"
shape="round"
size="small"
(click)="onPositionClick()"
class="location-button"
>
<ion-icon *ngIf="position !== null; else noLocationIcon" name="my_location"></ion-icon>
<ng-template #noLocationIcon>
<ion-icon
@@ -80,30 +86,12 @@
</ng-template>
</ion-button>
</div>
<stapps-map-item *ngIf="items.length === 1" [item]="items[0]" (onClose)="resetView()"></stapps-map-item>
</div>
<div class="map-buttons floating-buttons">
<ion-button
*ngIf="items.length > 1"
color="light"
shape="round"
size="small"
(click)="mapListModal.present()"
>
<ion-icon name="list"></ion-icon>&nbsp;&nbsp;{{ 'map.page.buttons.SHOW_LIST' | translate }}
</ion-button>
<ion-button color="light" shape="round" size="small" (click)="onPositionClick()">
<ion-icon *ngIf="position !== null; else noLocationIcon" name="my_location"></ion-icon>
<ng-template #noLocationIcon>
<ion-icon
*ngIf="locationStatus && locationStatus.location === 'denied'; else pendingLocationIcon"
name="location_disabled"
></ion-icon>
</ng-template>
<ng-template #pendingLocationIcon>
<ion-icon name="location_searching"></ion-icon>
</ng-template>
</ion-button>
<ion-card class="map-item">
<stapps-data-list-item *ngIf="items.length === 1" [item]="$any(items[0])"></stapps-data-list-item>
<ion-button fill="clear" class="close" (click)="resetView()">
<ion-icon size="22" name="close" slot="icon-only"></ion-icon>
</ion-button>
</ion-card>
</div>
<ion-modal [canDismiss]="true" #mapListModal>

View File

@@ -12,113 +12,87 @@
* 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 '../../../../theme/util/mixins';
ion-content {
// fixes the unexpected issue that the content is not fullscreen (behind the header)
position: absolute;
$bottom-offset: 7px; // no idea what happened here
div.map-container {
position: fixed;
width: 100%;
height: 100%;
}
& > div {
overflow: hidden;
}
.map-container {
width: 100%;
height: 100%;
}
ion-toolbar:first-of-type {
padding: 0 var(--spacing-md) var(--spacing-xs);
}
div.map-buttons {
.floating-content {
position: fixed;
z-index: 1000;
right: 0;
bottom: 0;
left: 0;
display: flex;
flex-flow: row-reverse wrap;
align-items: flex-end;
justify-content: space-between;
}
.map-buttons {
display: flex;
justify-content: flex-end;
ion-button {
// important for iOS
// TODO: find an option that is better suited for the iOS theme
--box-shadow: var(--map-box-shadow);
align-self: flex-end;
margin: 4px;
margin: var(--spacing-md);
&.location-button {
view-transition-name: location-button;
}
}
}
::ng-deep {
.stapps-location {
ion-icon {
width: 100%;
height: 100%;
color: #fd435c;
}
}
.map-item {
position: relative;
max-width: 550px;
margin: var(--spacing-md);
.stapps-device-location {
ion-icon {
width: 100%;
height: 100%;
color: #4387fd;
}
}
div.floating-content {
position: fixed;
z-index: 1000;
.close {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
display: block;
justify-content: center;
::ng-deep ion-item {
margin: 0;
}
}
@include ion-md-down {
.md {
ion-content {
--padding-bottom: $bottom-offset;
}
.floating-content {
bottom: $bottom-offset;
}
}
.map-buttons ion-button {
margin: var(--spacing-sm);
}
.map-item {
width: 100%;
padding: 0 var(--spacing-md) 8vh;
max-width: unset;
margin: 0;
ion-card {
margin: 0;
}
div.map-buttons {
display: flex;
justify-content: flex-end;
}
stapps-map-item {
position: center;
justify-self: center;
width: 550px;
margin: var(--spacing-sm) auto;
}
}
}
div.floating-buttons {
position: absolute;
z-index: 1000;
right: 10px;
bottom: 15px;
}
div.map-buttons.above {
display: none;
min-width: 70%;
}
@media (width <= 667px) {
div.map-buttons.above {
display: flex;
}
div.floating-content {
justify-content: normal;
padding: 0 var(--spacing-md) var(--spacing-lg);
stapps-map-item {
display: grid;
width: 100%;
}
}
div.map-buttons.floating-buttons {
display: none;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
}
}

View File

@@ -1,4 +0,0 @@
:host {
display: flex;
flex-direction: column;
}

View File

@@ -12,9 +12,9 @@
* 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 {Component, ElementRef, Input, OnInit, ViewChild} from '@angular/core';
import {Component, ElementRef, HostBinding, Input, OnInit, ViewChild} from '@angular/core';
import {Router} from '@angular/router';
import {SCPlace} from '@openstapps/core';
import {SCPlaceWithoutReferences, SCThingWithoutReferences} from '@openstapps/core';
import {geoJSON, Map, MapOptions, tileLayer} from 'leaflet';
import {MapProvider} from '../map.provider';
@@ -27,6 +27,8 @@ import {MapProvider} from '../map.provider';
templateUrl: './map-widget.html',
})
export class MapWidgetComponent implements OnInit {
@HostBinding('class.expand-when-space') expandWhenSpace = true;
/**
* A leaflet map showed
*/
@@ -45,7 +47,7 @@ export class MapWidgetComponent implements OnInit {
/**
* A place to show on the map
*/
@Input() place: SCPlace;
@Input() place: SCThingWithoutReferences & Pick<SCPlaceWithoutReferences, 'geo' | 'address'>;
/**
* Indicates if the expand button should be visible

View File

@@ -21,6 +21,10 @@
[leafletOptions]="options"
></div>
<div class="map-buttons" *ngIf="showExpandButton">
<ion-button color="primary" shape="round" size="small" [geoNavigation]="place">
<ion-icon name="directions" slot="start"></ion-icon>
{{'map.directions.TITLE' | translate}}
</ion-button>
<ion-button color="primary" shape="round" size="small" [routerLink]="['/map', place.uid]">
<ion-icon name="zoom_out_map"></ion-icon>
</ion-button>

View File

@@ -12,6 +12,12 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
:host {
position: relative;
width: auto;
height: 300px;
min-height: 300px;
}
div.map-container {
pointer-events: none;

View File

@@ -12,75 +12,23 @@
* 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 {Component, OnInit} from '@angular/core';
import {LangChangeEvent, TranslateService} from '@ngx-translate/core';
import {
SCAppConfigurationMenuCategory,
SCLanguage,
SCThingTranslator,
SCTranslations,
} from '@openstapps/core';
import {NavigationService} from './navigation.service';
import config from 'capacitor.config';
import {SettingsProvider} from '../../settings/settings.provider';
import {Component, inject} from '@angular/core';
import {BreakpointObserver} from '@angular/cdk/layout';
import {map} from 'rxjs/operators';
import {ConfigProvider} from '../../config/config.provider';
/**
* Generated class for the MenuPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/
@Component({
selector: 'stapps-navigation',
styleUrls: ['navigation.scss'],
templateUrl: 'navigation.html',
})
export class NavigationComponent implements OnInit {
showTabbar = true;
export class NavigationComponent {
/**
* Name of the app
* TODO: What was this for???
*/
appName = config.appName;
showTabBar$ = inject(BreakpointObserver)
.observe(['(min-width: 768px)'])
.pipe(map(({matches}) => !matches));
/**
* Possible languages to be used for translation
*/
language: keyof SCTranslations<SCLanguage>;
/**
* Menu entries from config module
*/
menu: SCAppConfigurationMenuCategory[];
/**
* Core translator
*/
translator: SCThingTranslator;
constructor(
public translateService: TranslateService,
private navigationService: NavigationService,
private settingsProvider: SettingsProvider,
private responsive: BreakpointObserver,
) {
translateService.onLangChange.subscribe((event: LangChangeEvent) => {
this.language = event.lang as keyof SCTranslations<SCLanguage>;
this.translator = new SCThingTranslator(this.language);
});
this.responsive.observe(['(min-width: 768px)']).subscribe(result => {
this.showTabbar = !result.matches;
});
}
async ngOnInit() {
this.language = (await this.settingsProvider.getValue(
'profile',
'language',
)) as keyof SCTranslations<SCLanguage>;
this.translator = new SCThingTranslator(this.language);
this.menu = await this.navigationService.getMenu();
}
constructor(readonly config: ConfigProvider) {}
}

View File

@@ -24,8 +24,8 @@
</ion-title>
</ion-toolbar>
</ion-header>
<ion-content *ngIf="menu">
<ion-list *ngFor="let category of menu; first as isFirst">
<ion-content *ngIf="config.app.menus">
<ion-list *ngFor="let category of config.app.menus; first as isFirst">
<ion-item
*ngIf="category.title !== ''"
[rootLink]="category.route"
@@ -34,11 +34,11 @@
class="menu-category"
>
<ion-icon slot="end" [name]="category.icon"></ion-icon>
<ion-label> {{ category.translations[language].title | titlecase }} </ion-label>
<ion-label> {{ 'title' | translateSimple: category | titlecase }} </ion-label>
</ion-item>
<ion-item *ngFor="let item of category.items" [rootLink]="item.route" [redirectedFrom]="item.route">
<ion-icon slot="end" [name]="item.icon"></ion-icon>
<ion-label> {{ item.translations[language].title | titlecase }} </ion-label>
<ion-label> {{ 'title' | translateSimple: item | titlecase }} </ion-label>
</ion-item>
</ion-list>
</ion-content>

View File

@@ -22,10 +22,11 @@ import {IonIconModule} from '../../../util/ion-icon/ion-icon.module';
import {TranslateModule} from '@ngx-translate/core';
import {RouterModule} from '@angular/router';
import {OfflineNoticeComponent} from './offline-notice.component';
import {ThingTranslateModule} from '../../../translation/thing-translate.module';
@NgModule({
declarations: [RootLinkDirective, NavigationComponent, TabsComponent, OfflineNoticeComponent],
imports: [CommonModule, IonicModule, IonIconModule, TranslateModule, RouterModule],
imports: [CommonModule, IonicModule, IonIconModule, TranslateModule, RouterModule, ThingTranslateModule],
exports: [TabsComponent, RootLinkDirective, NavigationComponent],
})
export class NavigationModule {}

View File

@@ -1,37 +0,0 @@
/*
* Copyright (C) 2022 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} from '@angular/core';
import {SCAppConfigurationMenuCategory} from '@openstapps/core';
import {ConfigProvider} from '../../config/config.provider';
import {NGXLogger} from 'ngx-logger';
@Injectable({
providedIn: 'root',
})
export class NavigationService {
constructor(private configProvider: ConfigProvider, private logger: NGXLogger) {}
async getMenu() {
let menu: SCAppConfigurationMenuCategory[] = [];
try {
menu = this.configProvider.getValue('menus') as SCAppConfigurationMenuCategory[];
} catch (error) {
this.logger.error(`error from loading menu entries: ${error}`);
}
return menu;
}
}

View File

@@ -12,93 +12,44 @@
* 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 {Component} from '@angular/core';
import {NavigationEnd, Router} from '@angular/router';
import {
SCAppConfigurationMenuCategory,
SCLanguage,
SCThingTranslator,
SCTranslations,
} from '@openstapps/core';
import {ChangeDetectionStrategy, Component, inject} from '@angular/core';
import {Event, NavigationEnd, Router} from '@angular/router';
import {SCAppConfigurationMenuCategory} from '@openstapps/core';
import {ConfigProvider} from '../../config/config.provider';
import {LangChangeEvent, TranslateService} from '@ngx-translate/core';
import {NGXLogger} from 'ngx-logger';
import {filter} from 'rxjs';
import {map, startWith} from 'rxjs/operators';
/**
* Finds a tab name based on urls
*/
function findTabFromUrl(url: string, menus: SCAppConfigurationMenuCategory[]): string {
if (url === '/') {
return menus[0]?.title ?? '';
}
return menus.find(category => url.includes(category.route))?.title ?? '';
}
/**
* Type guard for event
*/
function isNavigationEnd(event: Event): event is NavigationEnd {
return event instanceof NavigationEnd;
}
@Component({
selector: 'stapps-navigation-tabs',
templateUrl: 'tabs.template.html',
styleUrls: ['./tabs.component.scss'],
templateUrl: 'tabs.html',
styleUrls: ['./tabs.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TabsComponent {
/**
* Possible languages to be used for translation
*/
language: keyof SCTranslations<SCLanguage>;
menus = inject(ConfigProvider).app.menus.slice(0, 5);
/**
* Menu entries from config module
*/
menu: SCAppConfigurationMenuCategory[];
selectedTab$ = this.router.events.pipe(
filter(isNavigationEnd),
map(event => findTabFromUrl(event.url, this.menus)),
startWith(findTabFromUrl(this.router.url, this.menus)),
);
/**
* Core translator
*/
translator: SCThingTranslator;
/**
* Name of selected tab
*/
selectedTab: string;
constructor(
private readonly configProvider: ConfigProvider,
public translateService: TranslateService,
private readonly logger: NGXLogger,
private readonly router: Router,
) {
this.language = this.translateService.currentLang as keyof SCTranslations<SCLanguage>;
this.translator = new SCThingTranslator(this.language);
void this.loadMenuEntries();
this.router.events.subscribe((event: unknown) => {
if (event instanceof NavigationEnd) {
this.selectTab(event.url);
}
});
this.selectTab(router.url);
translateService.onLangChange?.subscribe((event: LangChangeEvent) => {
this.language = event.lang as keyof SCTranslations<SCLanguage>;
this.translator = new SCThingTranslator(this.language);
});
}
/**
* Loads menu entries from configProvider
*/
async loadMenuEntries() {
try {
const menus = (await this.configProvider.getValue('menus')) as SCAppConfigurationMenuCategory[];
const menu = menus.slice(0, 5);
if (menu) {
this.menu = menu;
}
} catch (error) {
this.logger.error(`error from loading menu entries: ${error}`);
}
}
/* eslint-disable @typescript-eslint/no-explicit-any */
selectTab(url: string) {
if (!this.menu) {
return;
}
if (url === '/') {
this.selectedTab = (this.menu[0] as any)?.title ?? '';
return;
}
const candidate = this.menu.slice(0, 5).find(category => url.includes(category.route));
this.selectedTab = candidate?.title ?? '';
}
constructor(private readonly router: Router) {}
}

View File

@@ -33,19 +33,19 @@
</ion-tab-bar>
-->
<ion-tab-bar slot="bottom" [selectedTab]="selectedTab">
<ion-tab-bar slot="bottom" [selectedTab]="selectedTab$ | async">
<ion-menu-toggle>
<ion-tab-button class="menu-button">
<ion-icon name="menu"></ion-icon>
</ion-tab-button>
</ion-menu-toggle>
<ion-tab-button
*ngFor="let category of menu; first as isFirst"
*ngFor="let category of menus; first as isFirst"
[rootLink]="category.route"
[redirectedFrom]="category.route"
[tab]="category.title"
>
<ion-icon [name]="category.icon"></ion-icon>
<ion-label>{{ category.translations[language].title | titlecase }}</ion-label>
<ion-label>{{ 'title' | translateSimple: category | titlecase }}</ion-label>
</ion-tab-button>
</ion-tab-bar>

View File

@@ -15,6 +15,7 @@
<ion-card
[routerLink]="['/data-detail', item.uid]"
[state]="{item}"
class="card"
[style.--background]="item.image ? 'url(' + item.image + ')' : undefined"
>

View File

@@ -18,9 +18,7 @@ import {FormsModule} from '@angular/forms';
import {RouterModule, Routes} from '@angular/router';
import {IonicModule} from '@ionic/angular';
import {TranslateModule} from '@ngx-translate/core';
import {ThingTranslateModule} from '../../translation/thing-translate.module';
import {ConfigProvider} from '../config/config.provider';
import {SettingsItemComponent} from './item/settings-item.component';
import {SettingsPageComponent} from './page/settings-page.component';
import {SettingTranslatePipe} from './setting-translate.pipe';
@@ -60,13 +58,6 @@ const settingsRoutes: Routes = [{path: 'settings', component: SettingsPageCompon
RouterModule.forChild(settingsRoutes),
UtilModule,
],
providers: [
ScheduleSyncService,
ConfigProvider,
SettingsProvider,
CalendarService,
ScheduleProvider,
ThingTranslatePipe,
],
providers: [ScheduleSyncService, SettingsProvider, CalendarService, ScheduleProvider, ThingTranslatePipe],
})
export class SettingsModule {}

Some files were not shown because too many files have changed in this diff Show More