2016-05-16 11:03:11 +02:00
|
|
|
import {Component, OnInit, ViewChild} from "@angular/core";
|
2016-12-27 00:36:38 +02:00
|
|
|
import {AuthenticationService} from "../model/network/authentication.service";
|
2017-06-04 15:25:08 +02:00
|
|
|
import {ActivatedRoute, Params, Router} from "@angular/router";
|
2016-03-20 17:54:30 +02:00
|
|
|
import {GalleryService} from "./gallery.service";
|
2016-04-09 15:19:25 +02:00
|
|
|
import {GalleryGridComponent} from "./grid/grid.gallery.component";
|
2016-05-03 21:04:57 +02:00
|
|
|
import {GallerySearchComponent} from "./search/search.gallery.component";
|
2016-05-16 11:03:11 +02:00
|
|
|
import {SearchTypes} from "../../../common/entities/AutoCompleteItem";
|
2017-06-04 15:25:08 +02:00
|
|
|
import {Config} from "../../../common/config/public/Config";
|
2017-06-21 11:46:23 +02:00
|
|
|
import {DirectoryDTO} from "../../../common/entities/DirectoryDTO";
|
2016-03-13 12:28:29 +02:00
|
|
|
|
|
|
|
@Component({
|
2017-06-10 22:32:56 +02:00
|
|
|
selector: 'gallery',
|
|
|
|
templateUrl: './gallery.component.html',
|
|
|
|
styleUrls: ['./gallery.component.css']
|
2016-03-13 12:28:29 +02:00
|
|
|
})
|
2016-05-09 17:04:56 +02:00
|
|
|
export class GalleryComponent implements OnInit {
|
2016-03-19 10:58:27 +02:00
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
@ViewChild(GallerySearchComponent) search: GallerySearchComponent;
|
|
|
|
@ViewChild(GalleryGridComponent) grid: GalleryGridComponent;
|
2016-05-09 17:04:56 +02:00
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
public showSearchBar: boolean = true;
|
2017-06-21 11:46:23 +02:00
|
|
|
public directories: DirectoryDTO[] = [];
|
2016-05-16 11:03:11 +02:00
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
constructor(public _galleryService: GalleryService,
|
|
|
|
private _authService: AuthenticationService,
|
|
|
|
private _router: Router,
|
|
|
|
private _route: ActivatedRoute) {
|
2016-05-10 21:33:58 +02:00
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
this.showSearchBar = Config.Client.Search.searchEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
if (!this._authService.isAuthenticated()) {
|
|
|
|
this._router.navigate(['login']);
|
|
|
|
return;
|
2016-03-19 10:58:27 +02:00
|
|
|
}
|
|
|
|
|
2017-06-21 11:46:23 +02:00
|
|
|
const dirSorter = (a: DirectoryDTO, b: DirectoryDTO) => {
|
|
|
|
return a.name.localeCompare(b.name);
|
|
|
|
};
|
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
this._route.params
|
2017-06-21 11:46:23 +02:00
|
|
|
.subscribe(async (params: Params) => {
|
2017-06-10 22:32:56 +02:00
|
|
|
let searchText = params['searchText'];
|
|
|
|
if (searchText && searchText != "") {
|
|
|
|
console.log("searching");
|
|
|
|
let typeString = params['type'];
|
|
|
|
|
|
|
|
if (typeString && typeString != "") {
|
|
|
|
console.log("with type");
|
|
|
|
let type: SearchTypes = <any>SearchTypes[typeString];
|
2017-06-21 11:46:23 +02:00
|
|
|
await this._galleryService.search(searchText, type);
|
|
|
|
this.directories = this._galleryService.content.searchResult.directories.sort(dirSorter);
|
2016-03-20 17:54:30 +02:00
|
|
|
return;
|
2017-06-10 22:32:56 +02:00
|
|
|
}
|
2016-05-16 11:03:11 +02:00
|
|
|
|
2017-06-21 11:46:23 +02:00
|
|
|
await this._galleryService.search(searchText);
|
|
|
|
this.directories = this._galleryService.content.searchResult.directories.sort(dirSorter);
|
2017-06-10 22:32:56 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-05-16 11:03:11 +02:00
|
|
|
|
2016-12-27 00:36:38 +02:00
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
let directoryName = params['directory'];
|
|
|
|
directoryName = directoryName ? directoryName : "";
|
2016-05-16 11:03:11 +02:00
|
|
|
|
2017-06-21 11:46:23 +02:00
|
|
|
await this._galleryService.getDirectory(directoryName);
|
|
|
|
this.directories = this._galleryService.content.directory.directories.sort(dirSorter);
|
2016-06-22 16:34:44 +02:00
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
});
|
2016-05-16 11:03:11 +02:00
|
|
|
|
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
}
|
2016-04-30 18:01:54 +02:00
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
onLightboxLastElement() {
|
|
|
|
this.grid.renderARow();
|
|
|
|
}
|
2016-07-04 16:58:10 +02:00
|
|
|
|
2016-04-26 15:10:05 +02:00
|
|
|
|
2016-03-13 12:28:29 +02:00
|
|
|
}
|
|
|
|
|