Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

refactor: remove unused variables #2086

Merged
merged 10 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions apps/dsp-app/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { PendoAnalyticsService } from '@dasch-swiss/vre/3rd-party-services/analytics';
Expand All @@ -11,9 +11,8 @@ import { LocalizationService } from '@dasch-swiss/vre/shared/app-helper-services
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit, OnDestroy {
export class AppComponent implements OnInit {
showCookieBanner = true;
session = false;

constructor(
private _router: Router,
Expand All @@ -38,10 +37,6 @@ export class AppComponent implements OnInit, OnDestroy {
}
}

ngOnDestroy(): void {
this._localizationService.destroy();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, destroying services is a good practice to avoid memory leaks and reset the state. If this service doesn't have any active subscriptions then it is ok to be removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does not


goToCookiePolicy() {
this._router.navigate([RouteConstants.cookiePolicy]);
}
Expand Down
6 changes: 3 additions & 3 deletions libs/vre/core/state/src/lib/ontologies/ontologies.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import {
} from '@dasch-swiss/dsp-js';
import { getAllEntityDefinitionsAsArray } from '@dasch-swiss/vre/3rd-party-services/api';
import { DspApiConnectionToken } from '@dasch-swiss/vre/core/config';
import { OntologyClassService, ProjectService, SortingService } from '@dasch-swiss/vre/shared/app-helper-services';
import { OntologyClassHelper, ProjectService, SortingService } from '@dasch-swiss/vre/shared/app-helper-services';
import { NotificationService } from '@dasch-swiss/vre/ui/notification';
import { Action, Actions, State, StateContext, ofActionSuccessful } from '@ngxs/store';
import { Action, Actions, ofActionSuccessful, State, StateContext } from '@ngxs/store';
import { of } from 'rxjs';
import { map, switchMap, take, tap } from 'rxjs/operators';
import { LoadListsInProjectAction } from '../lists/lists.actions';
Expand Down Expand Up @@ -154,7 +154,7 @@ export class OntologiesState {
.projectOntologies[projectIri].readOntologies.find(o => o.id === onto.id);
if (readOntology) {
ctx.dispatch(
OntologyClassService.GetReadOntologyClassesToDisplay(readOntology.classes).map(
OntologyClassHelper.GetReadOntologyClassesToDisplay(readOntology.classes).map(
resClass => new LoadClassItemsCountAction(onto.id, resClass.id)
)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { ClassDefinition } from '@dasch-swiss/dsp-js';
import { OntologyClassService, SortingService } from '@dasch-swiss/vre/shared/app-helper-services';
import { OntologyClassHelper, SortingService } from '@dasch-swiss/vre/shared/app-helper-services';

@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
Expand All @@ -16,7 +16,7 @@ export class OntologyClassesComponent {
@Input({ required: true }) projectMember!: boolean;

get classesToDisplay(): ClassDefinition[] {
const classesToDisplay = OntologyClassService.GetClassesToDisplay(this.resClasses);
const classesToDisplay = OntologyClassHelper.GetClassesToDisplay(this.resClasses);
return this._sortingService.keySortByAlphabetical(classesToDisplay, 'label');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export class FulltextSearchComponent implements OnInit, OnChanges, OnDestroy {
*/
setFocus(): void {
if (localStorage.getItem('prevSearch') !== null) {
this.prevSearch = this._sortingService.reverseArray(JSON.parse(localStorage.getItem('prevSearch')));
this.prevSearch = this._reverseArray(JSON.parse(localStorage.getItem('prevSearch')));
} else {
this.prevSearch = [];
}
Expand Down Expand Up @@ -432,4 +432,8 @@ export class FulltextSearchComponent implements OnInit, OnChanges, OnDestroy {
togglePhonePanel() {
this.displayPhonePanel = !this.displayPhonePanel;
}

private _reverseArray(value: Array<any>): Array<any> {
return value.slice().reverse();
}
}
1 change: 1 addition & 0 deletions libs/vre/resource-editor/representations/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ export * from './lib/third-party-iiif/third-party-iiif.component';
export * from './lib/edit-third-party-iiif-form/edit-third-party-iiif-form.component';
export * from './lib/edit-third-party-iiif-form/edit-third-party-iiif-types';
export * from './lib/video/disable-context-menu.directive';
export * from './lib/resource.util';
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import {
WriteValueResponse,
} from '@dasch-swiss/dsp-js';
import { DspApiConnectionToken } from '@dasch-swiss/vre/core/config';
import { ResourceUtil } from '@dasch-swiss/vre/shared/app-common';
import { mergeMap } from 'rxjs/operators';
import { FileRepresentation } from '../file-representation';
import {
ReplaceFileDialogComponent,
ReplaceFileDialogProps,
} from '../replace-file-dialog/replace-file-dialog.component';
import { RepresentationService } from '../representation.service';
import { ResourceUtil } from '../resource.util';

@Component({
selector: 'app-archive',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
WriteValueResponse,
} from '@dasch-swiss/dsp-js';
import { DspApiConnectionToken } from '@dasch-swiss/vre/core/config';
import { DspResource, ResourceUtil } from '@dasch-swiss/vre/shared/app-common';
import { DspResource } from '@dasch-swiss/vre/shared/app-common';
import { mergeMap } from 'rxjs/operators';
import { FileRepresentation } from '../file-representation';
import { getFileValue } from '../get-file-value';
Expand All @@ -20,6 +20,7 @@ import {
} from '../replace-file-dialog/replace-file-dialog.component';
import { RepresentationService } from '../representation.service';
import { ResourceFetcherService } from '../resource-fetcher.service';
import { ResourceUtil } from '../resource.util';

@Component({
selector: 'app-audio-more-button',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
WriteValueResponse,
} from '@dasch-swiss/dsp-js';
import { DspApiConnectionToken } from '@dasch-swiss/vre/core/config';
import { ResourceUtil } from '@dasch-swiss/vre/shared/app-common';
import { PdfViewerComponent } from 'ng2-pdf-viewer';
import { mergeMap, take } from 'rxjs/operators';
import { FileRepresentation } from '../file-representation';
Expand All @@ -20,6 +19,7 @@ import {
ReplaceFileDialogProps,
} from '../replace-file-dialog/replace-file-dialog.component';
import { RepresentationService } from '../representation.service';
import { ResourceUtil } from '../resource.util';

@Component({
selector: 'app-document',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import { AppConfigService } from '@dasch-swiss/vre/core/config';
import { AppError } from '@dasch-swiss/vre/core/error-handler';
import { AccessTokenService } from '@dasch-swiss/vre/core/session';
import { IKeyValuePairs, ResourceSelectors, UserSelectors } from '@dasch-swiss/vre/core/state';
import { ResourceUtil } from '@dasch-swiss/vre/shared/app-common';
import { Store } from '@ngxs/store';
import { Observable } from 'rxjs';
import { take } from 'rxjs/operators';
import { FileInfo } from './representation.types';
import { ResourceUtil } from './resource.util';

@Injectable({
providedIn: 'root',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
} from '@dasch-swiss/dsp-js';
import { DspApiConnectionToken, DspDialogConfig } from '@dasch-swiss/vre/core/config';
import { AppError } from '@dasch-swiss/vre/core/error-handler';
import { ResourceUtil } from '@dasch-swiss/vre/shared/app-common';
import { NotificationService } from '@dasch-swiss/vre/ui/notification';
import { filter, switchMap } from 'rxjs/operators';
import { EditThirdPartyIiifFormComponent } from '../edit-third-party-iiif-form/edit-third-party-iiif-form.component';
Expand All @@ -24,6 +23,7 @@ import {
} from '../replace-file-dialog/replace-file-dialog.component';
import { RepresentationService } from '../representation.service';
import { ResourceFetcherService } from '../resource-fetcher.service';
import { ResourceUtil } from '../resource.util';
import { OpenSeaDragonService } from './open-sea-dragon.service';

@Component({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import {
WriteValueResponse,
} from '@dasch-swiss/dsp-js';
import { DspApiConnectionToken } from '@dasch-swiss/vre/core/config';
import { ResourceUtil } from '@dasch-swiss/vre/shared/app-common';
import { mergeMap } from 'rxjs/operators';
import { FileRepresentation } from '../file-representation';
import {
ReplaceFileDialogComponent,
ReplaceFileDialogProps,
} from '../replace-file-dialog/replace-file-dialog.component';
import { RepresentationService } from '../representation.service';
import { ResourceUtil } from '../resource.util';

@Component({
selector: 'app-text',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
WriteValueResponse,
} from '@dasch-swiss/dsp-js';
import { DspApiConnectionToken } from '@dasch-swiss/vre/core/config';
import { ResourceUtil } from '@dasch-swiss/vre/shared/app-common';
import { NotificationService } from '@dasch-swiss/vre/ui/notification';
import { mergeMap } from 'rxjs/operators';
import { FileRepresentation } from '../file-representation';
Expand All @@ -21,6 +20,7 @@ import {
ReplaceFileDialogProps,
} from '../replace-file-dialog/replace-file-dialog.component';
import { RepresentationService } from '../representation.service';
import { ResourceUtil } from '../resource.util';

@Component({
selector: 'app-video-more-button',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { MatDialog } from '@angular/material/dialog';
import { ResourceClassDefinitionWithPropertyDefinition } from '@dasch-swiss/dsp-js';
import { DspDialogConfig } from '@dasch-swiss/vre/core/config';
import { LoadClassItemsCountAction, ProjectsSelectors, UserSelectors } from '@dasch-swiss/vre/core/state';
import { ResourceUtil } from '@dasch-swiss/vre/resource-editor/representations';
import {
EditResourceLabelDialogComponent,
EditResourceLabelDialogProps,
} from '@dasch-swiss/vre/resource-editor/resource-properties';
import { DspResource, ResourceUtil } from '@dasch-swiss/vre/shared/app-common';
import { DspResource } from '@dasch-swiss/vre/shared/app-common';
import { OntologyService, ProjectService } from '@dasch-swiss/vre/shared/app-helper-services';
import { Store } from '@ngxs/store';
import { combineLatest, Observable } from 'rxjs';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output, ViewContainerRef } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { AdminProjectsApiService } from '@dasch-swiss/vre/3rd-party-services/open-api';
import { ResourceFetcherService } from '@dasch-swiss/vre/resource-editor/representations';
import { ResourceFetcherService, ResourceUtil } from '@dasch-swiss/vre/resource-editor/representations';
import {
DeleteResourceDialogComponent,
DeleteResourceDialogProps,
Expand All @@ -10,7 +10,7 @@ import {
EraseResourceDialogComponent,
EraseResourceDialogProps,
} from '@dasch-swiss/vre/resource-editor/resource-properties';
import { DspResource, ResourceService, ResourceUtil } from '@dasch-swiss/vre/shared/app-common';
import { DspResource, ResourceService } from '@dasch-swiss/vre/shared/app-common';
import { NotificationService } from '@dasch-swiss/vre/ui/notification';
import { filter } from 'rxjs/operators';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { animate, state, style, transition, trigger } from '@angular/animations';
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { ResourceFetcherService } from '@dasch-swiss/vre/resource-editor/representations';
import { ResourceUtil } from '@dasch-swiss/vre/shared/app-common';
import { ResourceFetcherService, ResourceUtil } from '@dasch-swiss/vre/resource-editor/representations';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { PropertyValueService } from './property-value.service';
Expand Down
1 change: 0 additions & 1 deletion libs/vre/shared/app-common/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './lib/resource.service';
export * from './lib/resource.util';
export * from './lib/custom-regex';
export * from './lib/dsp-resource';
export * from './lib/property-info-values.interface';
Expand Down
19 changes: 0 additions & 19 deletions libs/vre/shared/app-common/src/lib/custom-regex.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
// @dynamic
// https://github.com/ng-packagr/ng-packagr/issues/641

export class CustomRegex {
public static readonly INT_REGEX = /^-?\d+$/;

public static readonly DECIMAL_REGEX = /^[-+]?[0-9]*\.?[0-9]*$/;

public static readonly URI_REGEX =
/^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,63}(:[0-9]{1,5})?(\/.*)?$/;

public static readonly COLOR_REGEX = /^#(?:[0-9a-fA-F]{6})$/;

public static readonly TIME_REGEX = /^([0-1]{1}[0-9]{1}|[2]{1}[0-4]{1}):{1}[0-5]{1}[0-9]{1}$/;

public static readonly GEONAME_REGEX = /^[0-9]{7}$/;

public static readonly EMAIL_REGEX =
/^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;

public static readonly PASSWORD_REGEX = /^(?=.*\d)(?=.*[a-zA-Z]).{8,}$/i;

public static readonly USERNAME_REGEX = /^[a-zA-Z0-9]+$/;

public static readonly SHORTNAME_REGEX = /^[a-zA-Z]+\S*$/;

public static readonly ONTOLOGYNAME_REGEX = /^(?![vV][0-9]|[0-9]|[\u00C0-\u017F]).[a-zA-Z0-9]+\S*$/;

// regex to check ontology name: shouldn't start with a number or with 'v' followed by a number, spaces or special characters are not allowed
public static readonly ID_NAME_REGEX = /^(?![vV]+[0-9])+^([a-zA-Z])[a-zA-Z0-9_.-]*$/;
}
3 changes: 1 addition & 2 deletions libs/vre/shared/app-helper-services/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
export * from './lib/base.service';
export * from './lib/component-communication-event.service';
export * from './lib/default-data/default-properties';
export * from './lib/default-data/default-resource-classes';
export * from './lib/ontology-class.service';
export * from './lib/ontology-class.helper';
export * from './lib/ontology.service';
export * from './lib/project.service';
export * from './lib/sorting.service';
Expand Down
10 changes: 0 additions & 10 deletions libs/vre/shared/app-helper-services/src/lib/base.service.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Base service should contain a common code for all services. Currently, it only has isDestroyed subject which should be used at the component level to check if the service was destroyed after a tab was closed or the page was refreshed, mostly for subscriptions. Sentry indicates that we have a lot of those kind of leaks and we should keep reducing them. So instead of deleting it, I suggest thinking about in which services we should use it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base service has been deleted, cause not used

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@ import it_CH from '@angular/common/locales/it-CH';
import { Injectable } from '@angular/core';
import { AvailableLanguages } from '@dasch-swiss/vre/core/config';
import { TranslateService } from '@ngx-translate/core';
import { BaseService } from './base.service';

@Injectable({
providedIn: 'root',
})
export class LocalizationService extends BaseService {
export class LocalizationService {
private readonly defaultLanguage = 'en';
private readonly localStorageLanguageKey = 'dsp_language';

private _locale: any;
get locale() {
return window.navigator.language ? window.navigator.language : this._locale;
}

set locale(value: string) {
this._locale = value;
this.setLocale(this._locale);
Expand All @@ -32,9 +27,7 @@ export class LocalizationService extends BaseService {
{ locale: 'it-CH', localeData: it_CH },
];

constructor(private translateService: TranslateService) {
super();
}
constructor(private translateService: TranslateService) {}

init() {
this.setDefaultLanguage();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { Injectable } from '@angular/core';
import { ClassDefinition, Constants } from '@dasch-swiss/dsp-js';
import { getAllEntityDefinitionsAsArray } from '@dasch-swiss/vre/3rd-party-services/api';

/**
* helper methods for the ontology editor
*/
@Injectable({
providedIn: 'root',
})
export class OntologyClassService {
export class OntologyClassHelper {
static GetClassesToDisplay(resClasses: ClassDefinition[]): ClassDefinition[] {
const classesToDisplay: ClassDefinition[] = [];
resClasses.forEach(resClass => {
Expand All @@ -24,6 +17,6 @@ export class OntologyClassService {
}

static GetReadOntologyClassesToDisplay(readOntologyClasses: { [index: string]: ClassDefinition }): ClassDefinition[] {
return OntologyClassService.GetClassesToDisplay(getAllEntityDefinitionsAsArray(readOntologyClasses));
return OntologyClassHelper.GetClassesToDisplay(getAllEntityDefinitionsAsArray(readOntologyClasses));
}
}
Loading
Loading