diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 3eb99f39c..baed2ed99 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -37,7 +37,10 @@ import { AppConfigService, DebugAppConfigService } from '@alfresco/adf-core'; -import { ContentModule } from '@alfresco/adf-content-services'; +import { + ContentModule, + CustomResourcesService +} from '@alfresco/adf-content-services'; import { AppComponent } from './app.component'; import { APP_ROUTES } from './app.routes'; @@ -74,6 +77,7 @@ import { LibraryMembershipDirective } from './directives/library-membership.dire import { ToggleJoinLibraryComponent } from './components/toolbar/toggle-join-library/toggle-join-library.component'; import { LibraryFavoriteDirective } from './directives/library-favorite.directive'; import { ToggleFavoriteLibraryComponent } from './components/toolbar/toggle-favorite-library/toggle-favorite-library.component'; +import { AppDataService } from './services/data.service'; @NgModule({ imports: [ @@ -123,6 +127,7 @@ import { ToggleFavoriteLibraryComponent } from './components/toolbar/toggle-favo providers: [ { provide: RouteReuseStrategy, useClass: AppRouteReuseStrategy }, { provide: AppConfigService, useClass: DebugAppConfigService }, + { provide: CustomResourcesService, useClass: AppDataService }, { provide: TRANSLATION_PROVIDER, multi: true, diff --git a/src/app/services/data.service.ts b/src/app/services/data.service.ts new file mode 100644 index 000000000..1af15f53a --- /dev/null +++ b/src/app/services/data.service.ts @@ -0,0 +1,110 @@ +/*! + * @license + * Alfresco Example Content Application + * + * Copyright (C) 2005 - 2018 Alfresco Software Limited + * + * This file is part of the Alfresco Example Content Application. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * The Alfresco Example Content Application is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The Alfresco Example Content Application 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ + +import { Injectable } from '@angular/core'; +import { CustomResourcesService } from '@alfresco/adf-content-services'; +import { + PaginationModel, + LogService, + AlfrescoApiService +} from '@alfresco/adf-core'; +import { Observable } from 'rxjs'; +import { PersonEntry, SearchRequest, ResultSetPaging } from 'alfresco-js-api'; + +@Injectable({ + providedIn: 'root' +}) +export class AppDataService extends CustomResourcesService { + constructor(private api: AlfrescoApiService, logService: LogService) { + super(api, logService); + } + + getRecentFiles( + personId: string, + pagination: PaginationModel + ): Observable { + const filters = [ + 'TYPE:"content"', + '-TYPE:"app:filelink"', + '-TYPE:"fm:post"', + '-TYPE:"cm:thumbnail"', + '-TYPE:"cm:failedThumbnail"', + '-TYPE:"cm:rating"', + '-TYPE:"dl:dataList"', + '-TYPE:"dl:todoList"', + '-TYPE:"dl:issue"', + '-TYPE:"fm:topic"', + '-TYPE:"fm:post"', + '-TYPE:"lnk:link"' + ]; + + return new Observable(observer => { + this.api.peopleApi.getPerson(personId).then( + (person: PersonEntry) => { + const username = person.entry.id; + const query: SearchRequest = { + query: { + query: '*', + language: 'afts' + }, + filterQueries: [ + { query: `cm:modified:[NOW/DAY-30DAYS TO NOW/DAY+1DAY]` }, + { query: `cm:modifier:${username} OR cm:creator:${username}` }, + { + query: filters.join(' AND ') + } + ], + include: ['path', 'properties', 'allowableOperations'], + sort: [ + { + type: 'FIELD', + field: 'cm:modified', + ascending: false + } + ], + paging: { + maxItems: pagination.maxItems, + skipCount: pagination.skipCount + } + }; + return this.api.searchApi.search(query).then( + searchResult => { + observer.next(searchResult); + observer.complete(); + }, + err => { + observer.error(err); + observer.complete(); + } + ); + }, + err => { + observer.error(err); + observer.complete(); + } + ); + }); + } +}