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

project: update properties and methods scopes #173

Merged
merged 1 commit into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions projects/ng-core-tester/src/app/app-config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ import { Injectable } from '@angular/core';
import { CoreConfigService } from '@rero/ng-core';
import { environment } from '../environments/environment';

/**
* Service for configuring the application.
*/
@Injectable({
providedIn: 'root'
})
export class AppConfigService extends CoreConfigService {
/**
* Constructor.
*/
constructor() {
super();
this.production = false;
Expand Down
59 changes: 57 additions & 2 deletions projects/ng-core-tester/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,48 +25,69 @@ import { DetailComponent } from './record/document/detail/detail.component';
import { DocumentComponent } from './record/document/document.component';
import { RouteService } from './routes/route.service';

/**
* Disallows access to admin functionalities.
*/
const adminModeCanNot = (): Observable<ActionStatus> => {
return of({
can: false,
message: ''
});
};

/**
* Allows access to admin functionalities.
*/
const adminModeCan = (): Observable<ActionStatus> => {
return of({
can: true,
message: ''
});
};

/**
* Whether user can add a record.
*/
const canAdd = (record: any): Observable<ActionStatus> => {
return of({
can: Math.random() >= 0.5,
message: ''
});
};

/**
* Whether user can update a record.
*/
const canUpdate = (record: any): Observable<ActionStatus> => {
return of({
can: Math.random() >= 0.5,
message: ''
});
};

/**
* Whether user can delete a record.
*/
const canDelete = (record: any): Observable<ActionStatus> => {
return of({
can: Math.random() >= 0.5,
message: `You <strong>cannot</strong> delete this record #${record.id} !`
});
};

/**
* Whether user can read a record.
*/
const canRead = (record: any): Observable<ActionStatus> => {
return of({
can: Math.random() >= 0.5,
message: ''
});
};

/**
* Custom configuration for form editor.
*/
const formFieldMap = (field: FormlyFieldConfig, jsonSchema: JSONSchema7): FormlyFieldConfig => {
// Populates "type" field with custom options
const formOptions = jsonSchema.form;
Expand All @@ -82,10 +103,19 @@ const formFieldMap = (field: FormlyFieldConfig, jsonSchema: JSONSchema7): Formly
return field;
};

/**
* Custom treatment for aggregations.
*/
const aggregations = (agg: object) => {
return of(agg);
};

/**
* Returned matched URL.
*
* @param url List of URL segments.
* @return Object representing the matched URL.
*/
export function matchedUrl(url: UrlSegment[]) {
const segments = [new UrlSegment(url[0].path, {})];

Expand All @@ -95,20 +125,35 @@ export function matchedUrl(url: UrlSegment[]) {
};
}

/**
* URL matchs document resource.
*
* @param url List of URL segments.
* @return Object representing the matched URL.
*/
export function documentsMatcher(url: Array<UrlSegment>) {
if (url[0].path === 'records' && url[1].path === 'documents') {
return matchedUrl(url);
}
return null;
}

/**
* URL matchs organisation resource.
*
* @param url List of URL segments.
* @return Object representing the matched URL.
*/
export function institutionsMatcher(url: Array<UrlSegment>) {
if (url[0].path === 'records' && url[1].path === 'institutions') {
return matchedUrl(url);
}
return null;
}

/**
* List of routes for application.
*/
const routes: Routes = [
{
path: '',
Expand Down Expand Up @@ -196,12 +241,22 @@ const routes: Routes = [
}
];

/**
* Routing module for application.
*/
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule {
constructor(private routeService: RouteService) {
this.routeService.initializeRoutes();
/**
* Constructor
*
* Intializes routes.
*
* @param _routeService Route service
*/
constructor(private _routeService: RouteService) {
this._routeService.initializeRoutes();
}
}
130 changes: 82 additions & 48 deletions projects/ng-core-tester/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,25 @@ import { CoreConfigService, RecordEvent, RecordService, TitleMetaService } from
import { BsLocaleService } from 'ngx-bootstrap';
import { ToastrService } from 'ngx-toastr';

/**
* Main component of the application.
*/
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent implements OnInit {
// Current lang of the application
lang: string = document.documentElement.lang;

// Available languages
languages: string[];

// If navigation is collapsed or not.
isCollapsed = true;

public linksMenu = {
// List of links in the navigation.
linksMenu = {
navCssClass: 'navbar-nav',
entries: [
{
Expand Down Expand Up @@ -69,63 +78,88 @@ export class AppComponent implements OnInit {
]
};

// List of languages in the navigation.
languagesMenu = {
navCssClass: 'navbar-nav',
entries: []
};

private activeLanguagesMenuItem;
// Active language.
private _activeLanguagesMenuItem: any;

/**
* Constructor.
* @param _translateService Translate service.
* @param _configService Configuration service.
* @param _titleMetaService Meta service.
* @param _recordService Record service.
* @param _toastrService Toast service.
* @param _bsLocaleService Locale service for bootstrap.
*/
constructor(
private translateService: TranslateService,
private configService: CoreConfigService,
private titleMetaService: TitleMetaService,
private recordService: RecordService,
private toastrService: ToastrService,
private bsLocaleService: BsLocaleService
) {
}
private _translateService: TranslateService,
private _configService: CoreConfigService,
private _titleMetaService: TitleMetaService,
private _recordService: RecordService,
private _toastrService: ToastrService,
private _bsLocaleService: BsLocaleService
) {
}

ngOnInit() {
this.initializeEvents();
this.translateService.use(this.lang);
this.languages = this.configService.languages;
for (const lang of this.languages) {
const data: any = {name: lang};
if (lang === this.lang) {
data.active = true;
this.activeLanguagesMenuItem = data;
}
this.languagesMenu.entries.push(data);
}
// Set default title window when application start
const prefix = this.configService.prefixWindow;
if (prefix) {
this.titleMetaService.setPrefix(prefix);
/**
* Component initialization.
*
* - Initializes listener to record changes.
* - Initializes languages and current language.
* - Sets title metadata.
*/
ngOnInit() {
this.initializeEvents();
this._translateService.use(this.lang);
this.languages = this._configService.languages;
for (const lang of this.languages) {
const data: any = { name: lang };
if (lang === this.lang) {
data.active = true;
this._activeLanguagesMenuItem = data;
}
this.titleMetaService.setTitle('Welcome');
this.languagesMenu.entries.push(data);
}

changeLang(item: any) {
this.translateService.use(item.name);
this.bsLocaleService.use(item.name);
delete(this.activeLanguagesMenuItem.active);
item.active = true;
this.activeLanguagesMenuItem = item;
// Set default title window when application start
const prefix = this._configService.prefixWindow;
if (prefix) {
this._titleMetaService.setPrefix(prefix);
}
this._titleMetaService.setTitle('Welcome');
}

private initializeEvents() {
this.recordService.onCreate$.subscribe((recordEvent: RecordEvent) => {
const pid = recordEvent.data.record.pid;
this.toastrService.info(`Call Record Event on create (Record Pid: ${pid})`);
});
this.recordService.onUpdate$.subscribe((recordEvent: RecordEvent) => {
const pid = recordEvent.data.record.pid;
this.toastrService.info(`Call Record Event on update (Record Pid: ${pid})`);
});
this.recordService.onDelete$.subscribe((recordEvent: RecordEvent) => {
const pid = recordEvent.data.pid;
this.toastrService.info(`Call Record Event on delete (Record Pid: ${pid})`);
});
}
/**
* Changes the languages.
* @param item Menu item representing a language.
*/
changeLang(item: any) {
this._translateService.use(item.name);
this._bsLocaleService.use(item.name);
delete (this._activeLanguagesMenuItem.active);
item.active = true;
this._activeLanguagesMenuItem = item;
}

/**
* Initializes listening of events when a record is changed.
*/
private initializeEvents() {
this._recordService.onCreate$.subscribe((recordEvent: RecordEvent) => {
const pid = recordEvent.data.record.pid;
this._toastrService.info(`Call Record Event on create (Record Pid: ${pid})`);
});
this._recordService.onUpdate$.subscribe((recordEvent: RecordEvent) => {
const pid = recordEvent.data.record.pid;
this._toastrService.info(`Call Record Event on update (Record Pid: ${pid})`);
});
this._recordService.onDelete$.subscribe((recordEvent: RecordEvent) => {
const pid = recordEvent.data.pid;
this._toastrService.info(`Call Record Event on delete (Record Pid: ${pid})`);
});
}
}
Loading