import { PublishFormDefaults } from "./../../culturize.conf" ; import { User } from "./User" ; import path = require ( "path" ) ; export enum Action { publish , validate , none } export enum Target { nginx , apache } /**
 * Encapsulates a request to publish a CSV file
 */ export class ActionRequest { public action : Action ; public csvPath : string ; public subdir : string ; public repoUrl : string ; public branch : string ; public commitMsg : string ; public user : User ; public target : Target ; public timestamp : string ; public advanced : boolean ; public noSubDir : boolean ; constructor param { string } csv param { string } dir param { string } url param { string } branch param { string } commitMsg constructor ( action , csv , dir , url , branch , commitMsg , target ) { this . action = action ; this . csvPath = csv ; this . subdir = dir ; this . repoUrl = url ; this . branch = branch ; this . commitMsg = commitMsg ; this . target = target ; const now = new Date ( ) ; this . timestamp = `${ now . getFullYear ( ) }-${ ( "0" + ( now . getMonth ( ) + 1 ) ) . slice ( - 2 ) }-${ ( "0" + now . getDate ( ) ) . slice ( - 2 ) } ` + `${ now . getHours ( ) }:${ now . getMinutes ( ) }:${ now . getSeconds ( ) }` ; this . advanced = false ; if ( this . branch !== PublishFormDefaults . branch ) { this . advanced = true ; } if ( this . commitMsg !== PublishFormDefaults . commitMessage ) { this . advanced = true ; } this . noSubDir = false ; if ( this . action === Action . publish && this . subdir === "" ) { this . noSubDir = true ; this . advanced = true ; } } public copyFrom ( other ) { this . action = other . action ; this . csvPath = other . csvPath ; this . subdir = other . subdir ; this . repoUrl = other . repoUrl ; this . branch = other . branch ; this . commitMsg = other . commitMsg ; this . target = other . target ; this . advanced = other . advanced ; this . noSubDir = other . noSubDir ; this . timestamp = other . timestamp ; } public loadData ( data ) { this . csvPath = data . csvPath ; this . subdir = data . subdir ; this . repoUrl = data . repoUrl ; this . branch = data . branch ; this . commitMsg = data . commitMsg ; this . target = data . forApache ? Target . apache : Target . nginx ; this . advanced = data . advanced ; this . noSubDir = data . noSubDir ; this . timestamp = data . timestamp ; } public dumpData ( ) { const data = { } ; data . csvPath = this . csvPath ; data . filename = path . basename ( this . csvPath ) ; data . subdir = this . subdir ; data . repoUrl = this . repoUrl ; data . branch = this . branch ; data . commitMsg = this . commitMsg ; data . forApache = this . target === Target . apache ? true : false ; data . advanced = this . advanced ; data . noSubDir = this . noSubDir ; data . timestamp = this . timestamp ; return data ; } returns public hasUser ( ) { return ( this . user !== undefined && this . user != null ) ; } returns public hasSelectedFile ( ) { return ( this . csvPath != null ) && ( this . csvPath !== "" ) ; } public hasSameArguments ( other ) { if ( this . csvPath === other . csvPath && this . subdir === other . subdir && this . repoUrl === other . repoUrl && this . branch === other . branch && this . commitMsg === other . commitMsg && this . target === other . target ) { return true ; } else { return false ; } } }