11import { Component , OnInit , Input } from '@angular/core' ;
2+ import { a } from '@angular/core/src/render3' ;
23import { Http , RequestOptions , Headers } from '@angular/http' ;
34import 'rxjs/add/operator/toPromise' ;
45declare var $ : any ;
@@ -26,6 +27,10 @@ export class AppComponent implements OnInit {
2627 Author_Add_Identifier : [ ] ,
2728 Author_Affiliation_Name : [ ] ,
2829 Author_Add_Affiliation_Name : [ ] ,
30+ Author_Affiliation_Period :[ ] ,
31+ Author_Affiliation_Period_Start :[ ] ,
32+ Author_Affiliation_Period_End :[ ] ,
33+ Author_Add_Affiliation_Period :[ ] ,
2934 Author_Affiliation : [ ] ,
3035 Author_Add_Affiliation : [ ] ,
3136 Author_Button_Delete : [ ] ,
@@ -34,9 +39,13 @@ export class AppComponent implements OnInit {
3439 Author_familyNmAndNm : [ ] ,
3540 Author_fullNm : [ ] ,
3641 Author_placeholder_authorId : [ ] ,
37- Author_Confirm_Msg : [ ]
42+ Author_Confirm_Msg : [ ] ,
43+ Author_Force_Change_Flag : [ ]
3844 } ;
3945 public deleteBtn :boolean = false ;
46+ public forceChangeCheck : boolean = false ;
47+ public forceChangeFlag : boolean = false ;
48+ public displayPkId : boolean = false ;
4049 //set data of page by json
4150 public authorJsonObj : any = {
4251 id : "" ,
@@ -53,7 +62,7 @@ export class AppComponent implements OnInit {
5362 ] ,
5463 authorIdInfo : [
5564 {
56- idType : "2 " ,
65+ idType : "1 " ,
5766 authorId : "" ,
5867 authorIdShowFlg : "true"
5968 }
@@ -76,6 +85,12 @@ export class AppComponent implements OnInit {
7685 affiliationNameLang : "ja" ,
7786 affiliationNameShowFlg : "true"
7887 }
88+ ] ,
89+ affiliationPeriodInfo : [
90+ {
91+ periodStart : null ,
92+ periodEnd : null
93+ }
7994 ]
8095 }
8196 ]
@@ -132,6 +147,7 @@ export class AppComponent implements OnInit {
132147 }
133148 ] ;
134149
150+ public placeholderForDate : string = "yyyy-mm-dd" ;
135151
136152 constructor ( private http : Http ,
137153 ) { }
@@ -146,12 +162,16 @@ export class AppComponent implements OnInit {
146162 }
147163
148164 /**
149- *
165+ * 初期値の取得
166+ *
150167 */
151168 getAuthorData ( ) {
152169 let urlStr = window . location . href ;
170+ // editの場合
153171 if ( urlStr . indexOf ( "edit" ) != - 1 ) {
154172 this . deleteBtn = true ;
173+ this . forceChangeCheck = true ;
174+ this . displayPkId = true ;
155175 let paramJson = { Id : "" }
156176 paramJson . Id = urlStr . substring ( urlStr . indexOf ( "=" ) ) . replace ( "=" , "" ) ;
157177 this . getDataOfAuthor ( paramJson ) . then (
@@ -160,7 +180,14 @@ export class AppComponent implements OnInit {
160180 console . log ( res )
161181 }
162182 ) . catch ( )
183+ // addの場合
163184 } else {
185+ // 初期値でweko_idの最大値+1を設定する。
186+ this . getDataOfMaxWekoId ( ) . then (
187+ res => {
188+ this . authorJsonObj . authorIdInfo [ 0 ] . authorId = String ( res . max_author_id + 1 ) ;
189+ }
190+ ) . catch ( )
164191 this . deleteBtn = false ;
165192 }
166193 }
@@ -316,6 +343,15 @@ export class AppComponent implements OnInit {
316343 this . authorJsonObj . affiliationInfo [ affiliationIndex ] . affiliationNameInfo . splice ( affiliationNameIndex , 1 )
317344 }
318345 }
346+ delAffiliationPeriodData ( affiliationIndex : string | number , affiliationPeriodIndex : any ) {
347+ //全部削除する場合
348+ if ( this . authorJsonObj . affiliationInfo [ affiliationIndex ] . affiliationPeriodInfo . length == 1 ) {
349+ let subAffiliationPeriodInfoObj = this . returnSubAffiliationPeriodInfoObj ( ) ;
350+ this . authorJsonObj . affiliationInfo [ affiliationIndex ] . affiliationPeriodInfo . splice ( affiliationPeriodIndex , 1 , subAffiliationPeriodInfoObj ) ;
351+ } else {
352+ this . authorJsonObj . affiliationInfo [ affiliationIndex ] . affiliationPeriodInfo . splice ( affiliationPeriodIndex , 1 )
353+ }
354+ }
319355 /**
320356 * affiliationを削除する
321357 * @@param 削除する位置情報
@@ -380,6 +416,21 @@ export class AppComponent implements OnInit {
380416 //行目を追加
381417 this . authorJsonObj . affiliationInfo [ affiliationIndex ] . affiliationNameInfo . push ( subAffiliationNameInfoObj ) ;
382418 }
419+ /**
420+ * 所属期間情報を追加する
421+ * @@param 追加する位置情報
422+ */
423+ addAffiliationPeriod ( affiliationIndex : any ) {
424+ //子対象を取得する
425+ let subAffiliationPeriodInfoObj = this . returnSubAffiliationPeriodInfoObj ( ) ;
426+ if ( this . authorJsonObj . affiliationInfo [ affiliationIndex ] . affiliationPeriodInfo === undefined ) {
427+ this . authorJsonObj . affiliationInfo [ affiliationIndex ] . affiliationPeriodInfo = [ ] ;
428+ }
429+ //行目を追加
430+ this . authorJsonObj . affiliationInfo [ affiliationIndex ] . affiliationPeriodInfo . push ( subAffiliationPeriodInfoObj ) ;
431+ }
432+
433+
383434 /**
384435 * 所属情報を追加する
385436 */
@@ -490,20 +541,36 @@ export class AppComponent implements OnInit {
490541 }
491542 return subAffiliationNameInfoObj ;
492543 }
544+ /**
545+ * affiliationPeriod情報を返す
546+ */
547+ returnSubAffiliationPeriodInfoObj ( ) : any {
548+ //所属期間情報
549+ let subAffiliationPeriodInfoObj = {
550+ periodStart : null ,
551+ periodEnd : null
552+ }
553+ return subAffiliationPeriodInfoObj ;
554+ }
493555 /**
494556 * affiliation情報を返す
495557 */
496558 returnSubAffiliationInfoObj ( ) : any {
497559 //所属情報
498560 let subAffiliationInfoObj = {
499561 "identifierInfo" : [ ] ,
500- "affiliationNameInfo" : [ ]
562+ "affiliationNameInfo" : [ ] ,
563+ "affiliationPeriodInfo" : [ ]
501564 }
502565 let subIdentifierInfoObj = this . returnSubIdentifierInfoObj ( ) ;
503566 subAffiliationInfoObj . identifierInfo . push ( subIdentifierInfoObj ) ;
504567
505568 let subAffiliationNameInfoObj = this . returnSubAffiliationNameInfoObj ( ) ;
506569 subAffiliationInfoObj . affiliationNameInfo . push ( subAffiliationNameInfoObj ) ;
570+
571+ let subAffiliationPeriodInfoObj = this . returnSubAffiliationPeriodInfoObj ( ) ;
572+ subAffiliationInfoObj . affiliationPeriodInfo . push ( subAffiliationPeriodInfoObj ) ;
573+
507574 return subAffiliationInfoObj ;
508575 }
509576
@@ -547,15 +614,15 @@ export class AppComponent implements OnInit {
547614 var urlArr = window . location . href . split ( '/' ) ;
548615 window . location . href = urlArr [ 0 ] + "//" + urlArr [ 2 ] + "/admin/authors/" ;
549616 } ) . catch ( res => {
550- alert ( res . msg ) ;
617+ alert ( JSON . parse ( res . _body ) . msg ) ;
551618 } )
552619 } else {
553620 this . postPageDataJson ( dbJson ) . then ( res => {
554621 // alert(res.msg); // Flash message one admin page instead
555622 var urlArr = window . location . href . split ( '/' ) ;
556623 window . location . href = urlArr [ 0 ] + "//" + urlArr [ 2 ] + "/admin/authors/" ;
557624 } ) . catch ( res => {
558- alert ( res . msg ) ;
625+ alert ( JSON . parse ( res . _body ) . msg ) ;
559626 } )
560627 }
561628 }
@@ -663,7 +730,9 @@ export class AppComponent implements OnInit {
663730 var urlArr = window . location . href . split ( '/' ) ;
664731 const url = urlArr [ 0 ] + "//" + urlArr [ 2 ] + "/api/authors/edit"
665732 return this . http
666- . post ( url , authorJsonObj )
733+ . post ( url ,
734+ { author : authorJsonObj ,
735+ forceChangeFlag : this . forceChangeFlag } )
667736 . toPromise ( )
668737 . then ( response => response . json ( ) as any )
669738 . catch ( this . handleError ) ;
@@ -693,7 +762,7 @@ export class AppComponent implements OnInit {
693762 . catch ( this . handleError ) ;
694763 }
695764 /**
696- *
765+ * call api (get author data by id)
697766 */
698767 getDataOfAuthor ( esid : any ) {
699768 var urlArr = window . location . href . split ( '/' ) ;
@@ -704,6 +773,20 @@ export class AppComponent implements OnInit {
704773 . then ( response => response . json ( ) as any )
705774 . catch ( this . handleError ) ;
706775 }
776+
777+ /**
778+ * call api (get max weko id)
779+ */
780+ getDataOfMaxWekoId ( ) {
781+ var urlArr = window . location . href . split ( '/' ) ;
782+ const url = urlArr [ 0 ] + "//" + urlArr [ 2 ] + "/api/authors/get_max_weko_id"
783+ return this . http
784+ . get ( url )
785+ . toPromise ( )
786+ . then ( response => response . json ( ) as any )
787+ . catch ( this . handleError ) ;
788+ }
789+
707790 /**
708791 * call api (get author prefix prefix)
709792 */
0 commit comments