diff --git a/backend/ProjectPath.ts b/backend/ProjectPath.ts index b2a77d0..77617d9 100644 --- a/backend/ProjectPath.ts +++ b/backend/ProjectPath.ts @@ -2,12 +2,12 @@ import * as path from "path"; import {Config} from "./config/Config"; class ProjectPathClass { - public Root:string; - public ImageFolder:string; - public ThumbnailFolder:string; + public Root: string; + public ImageFolder: string; + public ThumbnailFolder: string; - isAbsolutePath(pathStr) { - return path.resolve(pathStr) === path.normalize(pathStr).replace(RegExp(pathStr.sep + '$'), ''); + isAbsolutePath(pathStr: string) { + return path.resolve(pathStr) === path.normalize(pathStr); } constructor() { @@ -17,4 +17,4 @@ class ProjectPathClass { } } -export var ProjectPath = new ProjectPathClass(); \ No newline at end of file +export let ProjectPath = new ProjectPathClass(); \ No newline at end of file diff --git a/backend/config/Config.ts b/backend/config/Config.ts index 6fb5fe8..1994774 100644 --- a/backend/config/Config.ts +++ b/backend/config/Config.ts @@ -1,10 +1,8 @@ -/// - -import {ConfigLoader} from "./../../backend/config/ConfigLoader"; +import {ConfigLoader} from "./ConfigLoader"; import * as path from "path"; import {ConfigClass, DatabaseType} from "../../common/config/Config"; -export var Config = new ConfigClass(); +export let Config = new ConfigClass(); Config.Server = { port: 80, diff --git a/backend/config/ConfigLoader.ts b/backend/config/ConfigLoader.ts index a782342..4b00fdd 100644 --- a/backend/config/ConfigLoader.ts +++ b/backend/config/ConfigLoader.ts @@ -3,16 +3,16 @@ import * as optimist from "optimist"; export class ConfigLoader { - static init(configObject:any, configFilePath?:string, envAlias:Array> = []) { + static init(configObject: any, configFilePath?: string, envAlias: Array> = []) { this.processConfigFile(configFilePath, configObject); this.processArguments(configObject); this.processEnvVariables(configObject, envAlias); } - private static processEnvVariables(configObject:any, envAlias:Array>) { + private static processEnvVariables(configObject: any, envAlias: Array>) { let varAliases = {}; - envAlias.forEach((alias)=> { + envAlias.forEach((alias) => { if (process.env[alias[0]]) { varAliases[alias[1]] = process.env[alias[0]]; } @@ -21,24 +21,25 @@ export class ConfigLoader { this.loadObject(configObject, process.env); }; - private static processArguments(configObject:any) { + private static processArguments(configObject: any) { let argv = optimist.argv; delete(argv._); delete(argv.$0); this.processHierarchyVar(configObject, argv); }; - private static processHierarchyVar(configObject:any, vars:any) { + + private static processHierarchyVar(configObject: any, vars: any) { let config = {}; - Object.keys(vars).forEach((key)=> { + Object.keys(vars).forEach((key) => { let keyArray = key.split("-"); let value = vars[key]; //recursive settings - let setObject = (object, keyArray, value) => { + let setObject = (object: any, keyArray: Array, value: any): void => { let key = keyArray.shift(); - object[key] = {}; + object[key] = object[key] || {}; if (keyArray.length == 0) { //convert to boolean @@ -48,6 +49,7 @@ export class ConfigLoader { if (value.toLowerCase && value.toLowerCase() === "true") { value = true; } + object[key] = value; return; } @@ -57,10 +59,11 @@ export class ConfigLoader { setObject(config, keyArray, value); }); + this.loadObject(configObject, config); } - private static processConfigFile(configFilePath:string, configObject:any) { + private static processConfigFile(configFilePath: string, configObject: any) { if (typeof configFilePath !== 'undefined') { if (ConfigLoader.loadConfigFile(configFilePath, configObject) === false) { ConfigLoader.saveConfigFile(configFilePath, configObject); @@ -68,7 +71,7 @@ export class ConfigLoader { } }; - private static loadConfigFile(configFilePath, configObject):boolean { + private static loadConfigFile(configFilePath: string, configObject: any): boolean { if (fs.existsSync(configFilePath) === false) { return false; } @@ -84,7 +87,7 @@ export class ConfigLoader { } - private static saveConfigFile(configFilePath, configObject) { + private static saveConfigFile(configFilePath: string, configObject: any) { try { fs.writeFileSync(configFilePath, JSON.stringify(configObject, null, 4)); } catch (err) { @@ -92,8 +95,8 @@ export class ConfigLoader { } } - private static loadObject(targetObject, sourceObject) { - Object.keys(sourceObject).forEach((key)=> { + private static loadObject(targetObject: any, sourceObject: any) { + Object.keys(sourceObject).forEach((key) => { if (typeof targetObject[key] === "undefined") { return; } diff --git a/backend/middlewares/user/AuthenticationMWs.ts b/backend/middlewares/user/AuthenticationMWs.ts index 043983c..4229ae5 100644 --- a/backend/middlewares/user/AuthenticationMWs.ts +++ b/backend/middlewares/user/AuthenticationMWs.ts @@ -1,6 +1,4 @@ /// -/// - import {NextFunction, Request, Response} from "express"; import {Error, ErrorCodes} from "../../../common/entities/Error"; import {UserRoles, User} from "../../../common/entities/User"; @@ -12,6 +10,7 @@ export class AuthenticationMWs { public static authenticate(req:Request, res:Response, next:NextFunction) { if (Config.Client.authenticationRequired === false) { req.session.user = new User("", "", UserRoles.Admin); + return next(); } if (typeof req.session.user === 'undefined') { diff --git a/backend/model/DiskManger.ts b/backend/model/DiskManger.ts index 4b77a8a..36c05e1 100644 --- a/backend/model/DiskManger.ts +++ b/backend/model/DiskManger.ts @@ -1,6 +1,4 @@ /// - - import * as fs from "fs"; import * as path from "path"; import * as mime from "mime"; @@ -18,7 +16,7 @@ import { import {ProjectPath} from "../ProjectPath"; export class DiskManager { - public static scanDirectory(relativeDirectoryName, cb:(error:any, result:Directory) => void) { + public static scanDirectory(relativeDirectoryName: string, cb: (error: any, result: Directory) => void) { console.log("DiskManager: scanDirectory"); let directoryName = path.basename(relativeDirectoryName); let directoryParent = path.join(path.dirname(relativeDirectoryName), "/"); @@ -26,7 +24,7 @@ export class DiskManager { let directory = new Directory(1, directoryName, directoryParent, new Date(), [], []); - let promises:Array< Promise > = []; + let promises: Array< Promise > = []; fs.readdir(absoluteDirectoryName, function (err, list) { if (err) { @@ -44,7 +42,7 @@ export class DiskManager { if (DiskManager.isImage(fullFilePath)) { - let promise = DiskManager.loadPhotoMetadata(fullFilePath).then((photoMetadata)=> { + let promise = DiskManager.loadPhotoMetadata(fullFilePath).then((photoMetadata) => { directory.photos.push(new Photo(1, file, directory, photoMetadata)); }); @@ -52,14 +50,14 @@ export class DiskManager { } } - Promise.all(promises).then(()=> { + Promise.all(promises).then(() => { return cb(err, directory); }); }); } - private static isImage(fullPath) { + private static isImage(fullPath: string) { let imageMimeTypes = [ 'image/bmp', 'image/gif', @@ -72,7 +70,7 @@ export class DiskManager { 'image/x-windows-bmp' ]; - var extension = mime.lookup(fullPath); + let extension = mime.lookup(fullPath); if (imageMimeTypes.indexOf(extension) !== -1) { return true; @@ -113,8 +111,8 @@ export class DiskManager { } };*/ - private static loadPhotoMetadata(fullPath):Promise { - return new Promise((resolve:(metadata:PhotoMetadata)=>void, reject) => { + private static loadPhotoMetadata(fullPath: string): Promise { + return new Promise((resolve: (metadata: PhotoMetadata) => void, reject) => { fs.readFile(fullPath, function (err, data) { if (err) { reject(err); @@ -122,8 +120,8 @@ export class DiskManager { let exif = exif_parser.create(data).parse(); let iptcData = iptc(data); - let imageSize:ImageSize = {width: exif.imageSize.width, height: exif.imageSize.height}; - let cameraData:CameraMetadata = { + let imageSize: ImageSize = {width: exif.imageSize.width, height: exif.imageSize.height}; + let cameraData: CameraMetadata = { ISO: exif.tags.ISO, model: exif.tags.Modeol, maker: exif.tags.Make, @@ -132,14 +130,14 @@ export class DiskManager { focalLength: exif.tags.FocalLength, lens: exif.tags.LensModel, }; - let GPS:GPSMetadata = { + let GPS: GPSMetadata = { latitude: exif.tags.GPSLatitude, longitude: exif.tags.GPSLongitude, altitude: exif.tags.GPSAltitude }; - let positionData:PositionMetaData = { + let positionData: PositionMetaData = { GPSData: GPS, country: iptcData.country_or_primary_location_name, state: iptcData.province_or_state, @@ -147,24 +145,21 @@ export class DiskManager { }; //Decode characters to UTF8 - let decode = (s)=> { - for (var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l; - + let decode = (s: any) => { + for (let a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l; ((a = s[i][c](0)) & 0x80) && - (s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ? - o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "") ); return s.join(""); }; - let keywords:[string] = iptcData.keywords.map(s => decode(s)); - let creationDate:Date = iptcData.date_time; + let keywords: [string] = iptcData.keywords.map((s: string) => decode(s)); + let creationDate: Date = iptcData.date_time; console.log(keywords); - let metadata:PhotoMetadata = new PhotoMetadata(keywords, cameraData, positionData, imageSize, creationDate); + let metadata: PhotoMetadata = new PhotoMetadata(keywords, cameraData, positionData, imageSize, creationDate); resolve(metadata); } }); diff --git a/backend/model/IGalleryManager.ts b/backend/model/IGalleryManager.ts index 27b77e8..c3722ad 100644 --- a/backend/model/IGalleryManager.ts +++ b/backend/model/IGalleryManager.ts @@ -1,4 +1,4 @@ import {Directory} from "../../common/entities/Directory"; export interface IGalleryManager { - listDirectory(relativeDirectoryName, cb:(error:any, result:Directory) => void); + listDirectory(relativeDirectoryName: string, cb: (error: any, result: Directory) => void): void; } \ No newline at end of file diff --git a/backend/model/ISearchManager.ts b/backend/model/ISearchManager.ts index 017c6dc..1512ae1 100644 --- a/backend/model/ISearchManager.ts +++ b/backend/model/ISearchManager.ts @@ -1,7 +1,7 @@ import {AutoCompleteItem, SearchTypes} from "../../common/entities/AutoCompleteItem"; import {SearchResult} from "../../common/entities/SearchResult"; export interface ISearchManager { - autocomplete(text:string, cb:(error:any, result:Array) => void); - search(text:string, searchType:SearchTypes, cb:(error:any, result:SearchResult) => void); - instantSearch(text:string, cb:(error:any, result:SearchResult) => void); + autocomplete(text: string, cb: (error: any, result: Array) => void): void; + search(text: string, searchType: SearchTypes, cb: (error: any, result: SearchResult) => void): void; + instantSearch(text: string, cb: (error: any, result: SearchResult) => void): void; } \ No newline at end of file diff --git a/backend/model/IUserManager.ts b/backend/model/IUserManager.ts index 5b284a9..4433387 100644 --- a/backend/model/IUserManager.ts +++ b/backend/model/IUserManager.ts @@ -1,9 +1,9 @@ import {User, UserRoles} from "../../common/entities/User"; export interface IUserManager { - findOne(filter, cb:(error:any, result:User) => void); - find(filter, cb:(error:any, result:Array) => void); - createUser(user, cb:(error:any, result:User) => void); - deleteUser(id:number, cb:(error:any, result:string) => void); - changeRole(id:number, newRole:UserRoles, cb:(error:any) => void); - changePassword(request:any, cb:(error:any, result:string) => void); + findOne(filter: any, cb: (error: any, result: User) => void): void; + find(filter: any, cb: (error: any, result: Array) => void): void; + createUser(user: User, cb: (error: any, result: User) => void): void; + deleteUser(id: number, cb: (error: any, result: string) => void): void; + changeRole(id: number, newRole: UserRoles, cb: (error: any) => void): void; + changePassword(request: any, cb: (error: any, result: string) => void): void; } \ No newline at end of file diff --git a/backend/model/ObjectManagerRepository.ts b/backend/model/ObjectManagerRepository.ts index afa449b..734a6a1 100644 --- a/backend/model/ObjectManagerRepository.ts +++ b/backend/model/ObjectManagerRepository.ts @@ -1,5 +1,3 @@ -/// - import {IUserManager} from "./IUserManager"; import {IGalleryManager} from "./IGalleryManager"; import {ISearchManager} from "./ISearchManager"; diff --git a/backend/model/memory/GalleryManager.ts b/backend/model/memory/GalleryManager.ts index 91999da..43823d0 100644 --- a/backend/model/memory/GalleryManager.ts +++ b/backend/model/memory/GalleryManager.ts @@ -5,7 +5,7 @@ import {DiskManager} from "../DiskManger"; export class GalleryManager implements IGalleryManager { - public listDirectory(relativeDirectoryName, cb:(error:any, result:Directory) => void) { + public listDirectory(relativeDirectoryName: string, cb: (error: any, result: Directory) => void) { return DiskManager.scanDirectory(relativeDirectoryName, cb); } diff --git a/backend/model/memory/SearchManager.ts b/backend/model/memory/SearchManager.ts index 12e50a3..315f39d 100644 --- a/backend/model/memory/SearchManager.ts +++ b/backend/model/memory/SearchManager.ts @@ -5,15 +5,15 @@ import {SearchResult} from "../../../common/entities/SearchResult"; export class SearchManager implements ISearchManager { - autocomplete(text, cb:(error:any, result:Array) => void) { + autocomplete(text: string, cb: (error: any, result: Array) => void) { throw new Error("not implemented"); } - search(text, searchType:SearchTypes, cb:(error:any, result:SearchResult) => void) { + search(text: string, searchType: SearchTypes, cb: (error: any, result: SearchResult) => void) { throw new Error("not implemented"); } - instantSearch(text, cb:(error:any, result:SearchResult) => void) { + instantSearch(text: string, cb: (error: any, result: SearchResult) => void) { throw new Error("not implemented"); } diff --git a/backend/model/memory/UserManager.ts b/backend/model/memory/UserManager.ts index 9c17a63..1187b0f 100644 --- a/backend/model/memory/UserManager.ts +++ b/backend/model/memory/UserManager.ts @@ -1,6 +1,4 @@ /// - - import {User, UserRoles} from "../../../common/entities/User"; import {IUserManager} from "../IUserManager"; import {ProjectPath} from "../../ProjectPath"; @@ -10,9 +8,9 @@ import * as path from "path"; export class UserManager implements IUserManager { - private db:any = null; + private db: any = null; - generateId():string { + generateId(): string { function s4() { return Math.floor((1 + Math.random()) * 0x10000) .toString(16) @@ -43,8 +41,8 @@ export class UserManager implements IUserManager { } - public findOne(filter, cb:(error:any, result:User) => void) { - this.find(filter, (error, result:Array)=> { + public findOne(filter: any, cb: (error: any, result: User) => void) { + this.find(filter, (error, result: Array) => { if (error) { return cb(error, null); } @@ -56,14 +54,14 @@ export class UserManager implements IUserManager { }); } - public find(filter, cb:(error:any, result:Array) => void) { + public find(filter: any, cb: (error: any, result: Array) => void) { - let users = this.db.get("users").filter((u) => Utils.equalsFilter(u, filter)); + let users = this.db.get("users").filter((u: User) => Utils.equalsFilter(u, filter)); return cb(null, users); } - public createUser(user:User, cb:(error:any, result:User) => void = (e, r) => { + public createUser(user: User, cb: (error: any, result: User) => void = (e, r) => { }) { user.id = parseInt(this.db.get("idCounter")) + 1; this.db.put("idCounter", user.id); @@ -74,15 +72,15 @@ export class UserManager implements IUserManager { return cb(null, user); } - public deleteUser(id:number, cb:(error:any) => void) { - let users = this.db.get("users").filter((u) => u.id != id); + public deleteUser(id: number, cb: (error: any) => void) { + let users = this.db.get("users").filter((u: User) => u.id != id); this.db.put("users", users); return cb(null); } - public changeRole(id:number, newRole:UserRoles, cb:(error:any, result:string) => void) { + public changeRole(id: number, newRole: UserRoles, cb: (error: any, result: string) => void) { - let users:Array = this.db.get("users"); + let users: Array = this.db.get("users"); for (let i = 0; i < users.length; i++) { if (users[i].id == id) { @@ -93,7 +91,7 @@ export class UserManager implements IUserManager { this.db.put("users", users); } - public changePassword(request:any, cb:(error:any, result:string) => void) { + public changePassword(request: any, cb: (error: any, result: string) => void) { throw new Error("not implemented"); //TODO: implement } diff --git a/backend/model/memory/flat-file-db.ts b/backend/model/memory/flat-file-db.ts index cb5b6c9..3ce09f2 100644 --- a/backend/model/memory/flat-file-db.ts +++ b/backend/model/memory/flat-file-db.ts @@ -1,13 +1,13 @@ declare module "flat-file-db" { - export function sync(path:string):DB; + export function sync(path: string): DB; } declare interface DB { - sync(); - put(); - get(); - del(); - has(); - keys(); - close(); + sync(): any; + put(): any; + get(): any; + del(): any; + has(): any; + keys(): any; + close(): any; } \ No newline at end of file diff --git a/backend/routes/AdminRouter.ts b/backend/routes/AdminRouter.ts index b191350..03efbcc 100644 --- a/backend/routes/AdminRouter.ts +++ b/backend/routes/AdminRouter.ts @@ -1,10 +1,8 @@ -/// - import {AuthenticationMWs} from "../middlewares/user/AuthenticationMWs"; import {UserRoles} from "../../common/entities/User"; export class AdminRouter { - constructor(private app) { + constructor(private app: any) { this.addResetDB(); this.addIndexGallery(); diff --git a/backend/routes/ErrorRouter.ts b/backend/routes/ErrorRouter.ts index 41803cc..4f27a04 100644 --- a/backend/routes/ErrorRouter.ts +++ b/backend/routes/ErrorRouter.ts @@ -1,10 +1,10 @@ -/// - import {RenderingMWs} from "../middlewares/RenderingMWs"; import {Error, ErrorCodes} from "../../common/entities/Error"; +import Request = Express.Request; +import Response = Express.Response; export class ErrorRouter { - constructor(private app) { + constructor(private app: any) { this.addApiErrorHandler(); this.addGenericHandler(); @@ -17,7 +17,7 @@ export class ErrorRouter { }; private addGenericHandler() { - this.app.use((err, req, res, next) => { + this.app.use((err: any, req: Request, res: Response, next: Function) => { //Flush out the stack to the console console.error(err.stack); diff --git a/backend/routes/GalleryRouter.ts b/backend/routes/GalleryRouter.ts index 6deb03e..00133ee 100644 --- a/backend/routes/GalleryRouter.ts +++ b/backend/routes/GalleryRouter.ts @@ -1,12 +1,10 @@ -/// - import {AuthenticationMWs} from "../middlewares/user/AuthenticationMWs"; import {GalleryMWs} from "../middlewares/GalleryMWs"; import {RenderingMWs} from "../middlewares/RenderingMWs"; import {ThumbnailGeneratorMWs} from "../middlewares/ThumbnailGeneratorMWs"; export class GalleryRouter { - constructor(private app) { + constructor(private app: any) { this.addGetImageThumbnail(); this.addGetImage(); diff --git a/backend/routes/PublicRouter.ts b/backend/routes/PublicRouter.ts index 67cf554..73d8bb4 100644 --- a/backend/routes/PublicRouter.ts +++ b/backend/routes/PublicRouter.ts @@ -1,5 +1,3 @@ -/// - import * as _express from "express"; import {NextFunction, Request, Response} from "express"; import * as _path from "path"; @@ -24,8 +22,9 @@ export class PublicRouter { this.app.use(_express.static(_path.resolve(__dirname, './../../frontend'))); this.app.use('/node_modules', _express.static(_path.resolve(__dirname, './../../node_modules'))); + this.app.use('/common', _express.static(_path.resolve(__dirname, './../../common'))); - var renderIndex = (req:Request, res:Response) => { + const renderIndex = (req: Request, res: Response) => { res.render(_path.resolve(__dirname, './../../frontend/index.ejs'), res.tpl); }; diff --git a/backend/routes/SharingRouter.ts b/backend/routes/SharingRouter.ts index 9776002..f28490e 100644 --- a/backend/routes/SharingRouter.ts +++ b/backend/routes/SharingRouter.ts @@ -1,10 +1,8 @@ -/// - import {AuthenticationMWs} from "../middlewares/user/AuthenticationMWs"; import {UserRoles} from "../../common/entities/User"; export class SharingRouter { - constructor(private app) { + constructor(private app: any) { this.addGetSharing(); this.addUpdateSharing(); diff --git a/backend/routes/UserRouter.ts b/backend/routes/UserRouter.ts index df66c99..eec7ec7 100644 --- a/backend/routes/UserRouter.ts +++ b/backend/routes/UserRouter.ts @@ -1,5 +1,3 @@ -/// - import {UserMWs} from "../middlewares/user/UserMWs"; import {UserRoles} from "../../common/entities/User"; import {AuthenticationMWs} from "../middlewares/user/AuthenticationMWs"; diff --git a/backend/server.ts b/backend/server.ts index 7cc1aeb..4c4e98f 100644 --- a/backend/server.ts +++ b/backend/server.ts @@ -1,5 +1,3 @@ -/// - import * as _express from "express"; import * as _session from "express-session"; import * as _bodyParser from "body-parser"; @@ -11,16 +9,16 @@ import {GalleryRouter} from "./routes/GalleryRouter"; import {AdminRouter} from "./routes/AdminRouter"; import {ErrorRouter} from "./routes/ErrorRouter"; import {SharingRouter} from "./routes/SharingRouter"; -import {DatabaseType} from "./../common/config/Config"; +import {DatabaseType} from "../common/config/Config"; import {ObjectManagerRepository} from "./model/ObjectManagerRepository"; import {Config} from "./config/Config"; export class Server { - private debug:any; - private app:any; - private server:any; + private debug: any; + private app: any; + private server: any; constructor() { @@ -30,7 +28,7 @@ export class Server { this.app.set('view engine', 'ejs'); if (process.env.DEBUG) { - var _morgan = require('morgan'); + let _morgan = require('morgan'); this.app.use(_morgan('dev')); } @@ -90,7 +88,7 @@ export class Server { /** * Event listener for HTTP server "error" event. */ - private onError = (error) => { + private onError = (error: any) => { if (error.syscall !== 'listen') { throw error; } diff --git a/backend/tsconfig.json b/backend/tsconfig.json index 9adcce7..30660b3 100644 --- a/backend/tsconfig.json +++ b/backend/tsconfig.json @@ -1,15 +1,15 @@ { "compilerOptions": { "target": "es5", - "sourceMap": false, "module": "commonjs", "moduleResolution": "node", + "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, - "removeComments": false - }, - "exclude": [ - "node_modules", - "typings" - ] -} \ No newline at end of file + "lib": [ + "es2015", + "dom" + ], + "suppressImplicitAnyIndexErrors": true + } +} diff --git a/common/Utils.ts b/common/Utils.ts index 649b61a..2cce111 100644 --- a/common/Utils.ts +++ b/common/Utils.ts @@ -1,11 +1,11 @@ export class Utils { - static clone(object:T):T { + static clone(object: T): T { return JSON.parse(JSON.stringify(object)); } - static equalsFilter(object:any, filter:any):boolean { + static equalsFilter(object: any, filter: any): boolean { let keys = Object.keys(filter); for (let i = 0; i < keys.length; i++) { @@ -19,7 +19,7 @@ export class Utils { } - static concatUrls(...args:Array) { + static concatUrls(...args: Array) { let url = ""; for (let i = 0; i < args.length; i++) { if (args[i] === "" || typeof args[i] === "undefined") continue; @@ -34,8 +34,8 @@ export class Utils { return url.substring(0, url.length - 1); } - public static updateKeys(targetObject, sourceObject) { - Object.keys(sourceObject).forEach((key)=> { + public static updateKeys(targetObject: any, sourceObject: any) { + Object.keys(sourceObject).forEach((key) => { if (typeof targetObject[key] === "undefined") { return; } @@ -47,8 +47,8 @@ export class Utils { }); } - public static setKeys(targetObject, sourceObject) { - Object.keys(sourceObject).forEach((key)=> { + public static setKeys(targetObject: any, sourceObject: any) { + Object.keys(sourceObject).forEach((key) => { if (typeof targetObject[key] === "object") { Utils.setKeys(targetObject[key], sourceObject[key]); } else { @@ -57,8 +57,8 @@ export class Utils { }); } - public static setKeysForced(targetObject, sourceObject) { - Object.keys(sourceObject).forEach((key)=> { + public static setKeysForced(targetObject: any, sourceObject: any) { + Object.keys(sourceObject).forEach((key) => { if (typeof sourceObject[key] === "object") { if (typeof targetObject[key] === "undefined") { targetObject[key] = {}; @@ -70,8 +70,8 @@ export class Utils { }); } - public static enumToArray(EnumType):Array<{key:number;value:string;}> { - let arr:Array<{key:number;value:string;}> = []; + public static enumToArray(EnumType: any): Array<{key: number;value: string;}> { + let arr: Array<{key: number;value: string;}> = []; for (let enumMember in EnumType) { if (!EnumType.hasOwnProperty(enumMember)) { continue; @@ -85,12 +85,12 @@ export class Utils { } - public static findClosest(number:number, arr:Array) { + public static findClosest(number: number, arr: Array) { let curr = arr[0]; let diff = Math.abs(number - curr); - arr.forEach((value)=> { + arr.forEach((value) => { let newDiff = Math.abs(number - value); diff --git a/common/event/Event.ts b/common/event/Event.ts index 69fc992..5c4faa9 100644 --- a/common/event/Event.ts +++ b/common/event/Event.ts @@ -1,19 +1,19 @@ -function isFunction(functionToCheck) { - var getType = {}; +function isFunction(functionToCheck: any) { + let getType = {}; return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]'; } export class Event { - private handlers: { (data?: T): void; }[] = []; + private handlers: {(data?: T): void;}[] = []; - public on(handler: { (data?: T): void }) { - if(!isFunction(handler)){ + public on(handler: {(data?: T): void}) { + if (!isFunction(handler)) { throw new Error("Handler is not a function"); } this.handlers.push(handler); } - public off(handler: { (data?: T): void }) { + public off(handler: {(data?: T): void}) { this.handlers = this.handlers.filter(h => h !== handler); } diff --git a/common/tsconfig.json b/common/tsconfig.json index 44782a1..30660b3 100644 --- a/common/tsconfig.json +++ b/common/tsconfig.json @@ -1,13 +1,15 @@ { "compilerOptions": { "target": "es5", - "sourceMap": true, "module": "commonjs", + "moduleResolution": "node", + "sourceMap": true, "emitDecoratorMetadata": true, - "experimentalDecorators": true - }, - "exclude": [ - "./../node_modules", - "./../typings" - ] -} \ No newline at end of file + "experimentalDecorators": true, + "lib": [ + "es2015", + "dom" + ], + "suppressImplicitAnyIndexErrors": true + } +} diff --git a/frontend/app/admin/admin.component.ts b/frontend/app/admin/admin.component.ts index 8612b93..170f725 100644 --- a/frontend/app/admin/admin.component.ts +++ b/frontend/app/admin/admin.component.ts @@ -1,26 +1,17 @@ -/// - import {Component, OnInit} from "@angular/core"; -import {AuthenticationService} from "../model/network/authentication.service.ts"; -import {Router} from "@angular/router-deprecated"; -import {FrameComponent} from "../frame/frame.component"; +import {AuthenticationService} from "../model/network/authentication.service"; +import {Router} from "@angular/router"; import {UserRoles} from "../../../common/entities/User"; -import {FORM_DIRECTIVES} from "@angular/common"; -import {StringifyRole} from "./../pipes/StringifyRolePipe"; import {Config} from "../config/Config"; -import {UserMangerSettingsComponent} from "../settings/usermanager/usermanager.settings.component"; - @Component({ selector: 'admin', templateUrl: 'app/admin/admin.component.html', - styleUrls: ['app/admin/admin.component.css'], - directives: [FrameComponent, FORM_DIRECTIVES, UserMangerSettingsComponent], - pipes: [StringifyRole] + styleUrls: ['app/admin/admin.component.css'] }) export class AdminComponent implements OnInit { - userManagementEnable:boolean = false; + userManagementEnable: boolean = false; - constructor(private _authService:AuthenticationService, private _router:Router) { + constructor(private _authService: AuthenticationService, private _router: Router) { this.userManagementEnable = Config.Client.authenticationRequired; } diff --git a/frontend/app/app.component.ts b/frontend/app/app.component.ts index f2a144e..8e36fe8 100644 --- a/frontend/app/app.component.ts +++ b/frontend/app/app.component.ts @@ -1,83 +1,29 @@ -/// - import {Component, OnInit} from "@angular/core"; -import {LoginComponent} from "./login/login.component"; -import {AuthenticationService} from "./model/network/authentication.service.ts"; -import {GalleryComponent} from "./gallery/gallery.component"; +import {AuthenticationService} from "./model/network/authentication.service"; import {User} from "../../common/entities/User"; -import {Router, RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from "@angular/router-deprecated"; -import {HTTP_PROVIDERS} from "@angular/http"; -import {UserService} from "./model/network/user.service.ts"; -import {GalleryService} from "./gallery/gallery.service"; -import {AdminComponent} from "./admin/admin.component"; -import {NetworkService} from "./model/network/network.service"; -import {ThumbnailLoaderService} from "./gallery/grid/thumnailLoader.service"; -import {GalleryCacheService} from "./gallery/cache.gallery.service"; -import {FullScreenService} from "./gallery/fullscreen.service"; - +import {Router} from "@angular/router"; @Component({ selector: 'pi-gallery2-app', template: ``, - directives: [ROUTER_DIRECTIVES], - providers: [ - HTTP_PROVIDERS, - ROUTER_PROVIDERS, - NetworkService, - UserService, - GalleryCacheService, - GalleryService, - AuthenticationService, - ThumbnailLoaderService, - FullScreenService] + }) -@RouteConfig([ - { - path: '/', - redirectTo: ["Login"] - }, - { - path: '/login', - name: 'Login', - component: LoginComponent, - useAsDefault: true - }, - { - path: '/admin', - name: 'Admin', - component: AdminComponent - }, - { - path: '/gallery', - redirectTo: ["Gallery", {directory: ""}] - }, - { - path: '/gallery/:directory', - name: 'Gallery', - component: GalleryComponent - }, - { - path: '/search/:searchText', - name: 'Search', - component: GalleryComponent - }, -]) export class AppComponent implements OnInit { - constructor(private _router:Router, private _authenticationService:AuthenticationService) { + constructor(private _router: Router, private _authenticationService: AuthenticationService) { } ngOnInit() { - this._authenticationService.OnUserChanged.on((user:User) => { + this._authenticationService.OnUserChanged.on((user: User) => { if (user != null) { - if (this._router.isRouteActive(this._router.generate(['Login']))) { + if (this._router.isActive('login', true)) { console.log("routing"); - this._router.navigate(["Gallery", {directory: ""}]); + this._router.navigate(["gallery", ""]); } } else { - if (!this._router.isRouteActive(this._router.generate(['Login']))) { + if (this._router.isActive('login', true)) { console.log("routing"); - this._router.navigate(["Login"]); + this._router.navigate(["login"]); } } diff --git a/frontend/app/app.module.ts b/frontend/app/app.module.ts new file mode 100644 index 0000000..6849b13 --- /dev/null +++ b/frontend/app/app.module.ts @@ -0,0 +1,65 @@ +import {NgModule} from "@angular/core"; +import {BrowserModule} from "@angular/platform-browser"; +import {FormsModule} from "@angular/forms"; +import {HttpModule} from "@angular/http"; +import {AppComponent} from "./app.component"; +import {appRoutes} from "./app.routing"; +import {UserService} from "./model/network/user.service"; +import {GalleryService} from "./gallery/gallery.service"; +import {NetworkService} from "./model/network/network.service"; +import {ThumbnailLoaderService} from "./gallery/grid/thumnailLoader.service"; +import {GalleryCacheService} from "./gallery/cache.gallery.service"; +import {FullScreenService} from "./gallery/fullscreen.service"; +import {AuthenticationService} from "./model/network/authentication.service"; +import {UserMangerSettingsComponent} from "./settings/usermanager/usermanager.settings.component"; +import {FrameComponent} from "./frame/frame.component"; +import {GalleryLightboxPhotoComponent} from "./gallery/lightbox/photo/photo.lightbox.gallery.component"; +import {GalleryPhotoLoadingComponent} from "./gallery/grid/photo/loading/loading.photo.grid.gallery.component"; +import {GalleryNavigatorComponent} from "./gallery/navigator/navigator.gallery.component"; +import {GallerySearchComponent} from "./gallery/search/search.gallery.component"; +import {GalleryLightboxComponent} from "./gallery/lightbox/lightbox.gallery.component"; +import {GalleryDirectoryComponent} from "./gallery/directory/directory.gallery.component"; +import {GalleryGridComponent} from "./gallery/grid/grid.gallery.component"; +import {GalleryPhotoComponent} from "./gallery/grid/photo/photo.grid.gallery.component"; +import {LoginComponent} from "./login/login.component"; +import {AdminComponent} from "./admin/admin.component"; +import {GalleryComponent} from "./gallery/gallery.component"; +import {StringifyRole} from "./pipes/StringifyRolePipe"; + +@NgModule({ + imports: [ + BrowserModule, + FormsModule, + HttpModule, + appRoutes + ], + declarations: [AppComponent, + LoginComponent, + AdminComponent, + GalleryComponent, + FrameComponent, + UserMangerSettingsComponent, + GalleryLightboxPhotoComponent, + GalleryPhotoLoadingComponent, + GalleryGridComponent, + GalleryDirectoryComponent, + GalleryLightboxComponent, + FrameComponent, + GallerySearchComponent, + GalleryNavigatorComponent, + GalleryPhotoComponent, + FrameComponent, + StringifyRole], + providers: [ + NetworkService, + UserService, + GalleryCacheService, + GalleryService, + AuthenticationService, + ThumbnailLoaderService, + FullScreenService], + + bootstrap: [AppComponent] +}) +export class AppModule { +} \ No newline at end of file diff --git a/frontend/app/app.routing.ts b/frontend/app/app.routing.ts new file mode 100644 index 0000000..45d6790 --- /dev/null +++ b/frontend/app/app.routing.ts @@ -0,0 +1,32 @@ +import {ModuleWithProviders} from "@angular/core"; +import {Routes, RouterModule} from "@angular/router"; +import {LoginComponent} from "./login/login.component"; +import {GalleryComponent} from "./gallery/gallery.component"; +import {AdminComponent} from "./admin/admin.component"; + +const ROUTES: Routes = [ + { + path: 'login', + component: LoginComponent + }, + { + path: 'admin', + component: AdminComponent + }, + { + path: 'gallery/:directory', + component: GalleryComponent + }, + { + path: 'gallery', + component: GalleryComponent + }, + { + path: 'search/:searchText', + component: GalleryComponent + }, + {path: '', redirectTo: '/login', pathMatch: 'full'} +]; + +export const appRoutes: ModuleWithProviders = RouterModule.forRoot(ROUTES); + diff --git a/frontend/app/config/Config.ts b/frontend/app/config/Config.ts index 9930701..f92d358 100644 --- a/frontend/app/config/Config.ts +++ b/frontend/app/config/Config.ts @@ -2,10 +2,10 @@ import {ConfigClass} from "../../../common/config/Config"; import {Utils} from "../../../common/Utils"; declare module ServerInject { - export var ConfigInject; + export let ConfigInject: ConfigClass; } -export var Config = new ConfigClass(); +export let Config = new ConfigClass(); if (typeof ServerInject !== "undefined" && typeof ServerInject.ConfigInject !== "undefined") { Utils.updateKeys(Config.Client, ServerInject.ConfigInject); diff --git a/frontend/app/frame/frame.component.html b/frontend/app/frame/frame.component.html index aa3fd21..e582e70 100644 --- a/frontend/app/frame/frame.component.html +++ b/frontend/app/frame/frame.component.html @@ -12,8 +12,8 @@