2017-09-21 15:48:00 +01:00
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
2018-01-22 10:31:03 +00:00
import $ from 'jquery' ;
2018-06-15 14:25:05 +01:00
import { A } from '@ember/array' ;
2017-11-16 13:28:05 +00:00
import { computed } from '@ember/object' ;
2018-01-22 10:31:03 +00:00
import { notEmpty } from '@ember/object/computed' ;
2017-11-16 13:28:05 +00:00
import { inject as service } from '@ember/service' ;
2018-06-15 14:25:05 +01:00
import Modals from '../../mixins/modal' ;
import Tooltips from '../../mixins/tooltip' ;
2018-03-15 17:11:53 +00:00
import Component from '@ember/component' ;
2017-09-21 15:48:00 +01:00
2018-06-15 14:25:05 +01:00
export default Component . extend ( Modals , Tooltips , {
documentService : service ( 'document' ) ,
2017-11-16 13:28:05 +00:00
sessionService : service ( 'session' ) ,
2018-06-15 14:25:05 +01:00
categoryService : service ( 'category' ) ,
2018-06-25 19:43:29 +01:00
router : service ( ) ,
2018-01-22 10:31:03 +00:00
contributorMsg : '' ,
approverMsg : '' ,
userChanges : notEmpty ( 'contributorMsg' ) ,
isApprover : computed ( 'permissions' , function ( ) {
return this . get ( 'permissions.documentApprove' ) ;
} ) ,
2018-06-25 19:43:29 +01:00
isSpaceAdmin : computed ( 'permissions' , function ( ) {
return this . get ( 'permissions.spaceOwner' ) || this . get ( 'permissions.spaceManage' ) ;
} ) ,
2018-01-22 10:31:03 +00:00
changeControlMsg : computed ( 'document.protection' , function ( ) {
let p = this . get ( 'document.protection' ) ;
let constants = this . get ( 'constants' ) ;
let msg = '' ;
2018-05-03 12:49:49 +01:00
2018-01-22 10:31:03 +00:00
switch ( p ) {
case constants . ProtectionType . None :
msg = constants . ProtectionType . NoneLabel ;
break ;
case constants . ProtectionType . Lock :
msg = constants . ProtectionType . LockLabel ;
break ;
case constants . ProtectionType . Review :
msg = constants . ProtectionType . ReviewLabel ;
break ;
}
return msg ;
} ) ,
approvalMsg : computed ( 'document.{protection,approval}' , function ( ) {
let p = this . get ( 'document.protection' ) ;
let a = this . get ( 'document.approval' ) ;
let constants = this . get ( 'constants' ) ;
let msg = '' ;
if ( p === constants . ProtectionType . Review ) {
switch ( a ) {
case constants . ApprovalType . Anybody :
msg = constants . ApprovalType . AnybodyLabel ;
break ;
case constants . ApprovalType . Majority :
msg = constants . ApprovalType . MajorityLabel ;
break ;
case constants . ApprovalType . Unanimous :
msg = constants . ApprovalType . UnanimousLabel ;
break ;
}
}
return msg ;
2018-05-03 12:49:49 +01:00
} ) ,
2018-01-22 10:31:03 +00:00
2017-09-21 15:48:00 +01:00
didReceiveAttrs ( ) {
this . _super ( ... arguments ) ;
2018-06-15 14:25:05 +01:00
2018-01-22 10:31:03 +00:00
this . workflowStatus ( ) ;
2018-06-15 14:25:05 +01:00
this . popovers ( ) ;
this . load ( ) ;
2017-09-22 17:23:14 +01:00
} ,
2017-12-05 10:46:53 +00:00
didInsertElement ( ) {
this . _super ( ... arguments ) ;
2018-06-15 14:25:05 +01:00
this . popovers ( ) ;
this . renderTooltips ( ) ;
} ,
2017-12-05 10:46:53 +00:00
2018-06-15 14:25:05 +01:00
willDestroyElement ( ) {
this . _super ( ... arguments ) ;
2017-12-05 10:46:53 +00:00
2018-06-15 14:25:05 +01:00
$ ( '#document-lifecycle-popover' ) . popover ( 'dispose' ) ;
$ ( '#document-protection-popover' ) . popover ( 'dispose' ) ;
this . removeTooltips ( ) ;
2017-12-05 10:46:53 +00:00
} ,
2018-06-15 14:25:05 +01:00
popovers ( ) {
let constants = this . get ( 'constants' ) ;
2017-12-05 10:46:53 +00:00
2018-06-25 19:43:29 +01:00
if ( this . get ( 'permissions.documentLifecycle' ) ) {
$ ( '#document-lifecycle-popover' ) . addClass ( 'cursor-pointer' ) ;
} else {
$ ( '#document-lifecycle-popover' ) . popover ( 'dispose' ) ;
$ ( '#document-lifecycle-popover' ) . removeClass ( 'cursor-pointer' ) ;
$ ( '#document-lifecycle-popover' ) . popover ( {
html : true ,
title : 'Lifecycle' ,
content : "<p>Draft — restricted visiblity and not searchable</p><p>Live — document visible to all</p><p>Archived — not visible or searchable</p>" ,
placement : 'top' ,
trigger : 'hover click'
} ) ;
}
2018-06-15 14:25:05 +01:00
2018-06-25 19:43:29 +01:00
if ( this . get ( 'permissions.documentApprove' ) ) {
$ ( '#document-protection-popover' ) . addClass ( 'cursor-pointer' ) ;
} else {
$ ( '#document-protection-popover' ) . popover ( 'dispose' ) ;
$ ( '#document-protection-popover' ) . removeClass ( 'cursor-pointer' ) ;
2017-12-04 17:25:33 +00:00
2018-06-25 19:43:29 +01:00
let ccMsg = ` <p> ${ this . changeControlMsg } </p> ` ;
2018-06-15 14:25:05 +01:00
2018-06-25 19:43:29 +01:00
if ( this . get ( 'document.protection' ) === constants . ProtectionType . Review ) {
ccMsg += '<ul>'
ccMsg += ` <li> ${ this . approvalMsg } </li> ` ;
if ( this . get ( 'userChanges' ) ) ccMsg += ` <li>Your contributions: ${ this . contributorMsg } </li> ` ;
if ( this . get ( 'isApprover' ) && this . get ( 'approverMsg.length' ) > 0 ) ccMsg += ` <li> ${ this . approverMsg } </li> ` ;
ccMsg += '</ul>'
}
2017-12-04 17:25:33 +00:00
2018-06-25 19:43:29 +01:00
$ ( '#document-protection-popover' ) . popover ( {
html : true ,
title : 'Change Control' ,
content : ccMsg ,
placement : 'top' ,
trigger : 'hover click'
} ) ;
}
2017-09-21 15:48:00 +01:00
} ,
2018-01-22 10:31:03 +00:00
workflowStatus ( ) {
let pages = this . get ( 'pages' ) ;
let contributorMsg = '' ;
let userPendingCount = 0 ;
let userReviewCount = 0 ;
let userRejectedCount = 0 ;
let approverMsg = '' ;
let approverPendingCount = 0 ;
let approverReviewCount = 0 ;
let approverRejectedCount = 0 ;
pages . forEach ( ( item ) => {
if ( item . get ( 'userHasChangePending' ) ) userPendingCount += 1 ;
if ( item . get ( 'userHasChangeAwaitingReview' ) ) userReviewCount += 1 ;
if ( item . get ( 'userHasChangeRejected' ) ) userRejectedCount += 1 ;
if ( item . get ( 'changePending' ) ) approverPendingCount += 1 ;
if ( item . get ( 'changeAwaitingReview' ) ) approverReviewCount += 1 ;
if ( item . get ( 'changeRejected' ) ) approverRejectedCount += 1 ;
} ) ;
if ( userPendingCount > 0 || userReviewCount > 0 || userRejectedCount > 0 ) {
let label = userPendingCount === 1 ? 'change' : 'changes' ;
contributorMsg = ` ${ userPendingCount } ${ label } progressing, ${ userReviewCount } awaiting review, ${ userRejectedCount } rejected ` ;
}
this . set ( 'contributorMsg' , contributorMsg ) ;
if ( approverPendingCount > 0 || approverReviewCount > 0 || approverRejectedCount > 0 ) {
let label = approverPendingCount === 1 ? 'change' : 'changes' ;
approverMsg = ` ${ approverPendingCount } ${ label } progressing, ${ approverReviewCount } awaiting review, ${ approverRejectedCount } rejected ` ;
}
2017-09-22 17:23:14 +01:00
2018-06-15 14:25:05 +01:00
this . set ( 'approverMsg' , approverMsg ) ;
this . set ( 'selectedVersion' , this . get ( 'versions' ) . findBy ( 'documentId' , this . get ( 'document.id' ) ) ) ;
2017-12-05 10:46:53 +00:00
2018-06-15 14:25:05 +01:00
this . popovers ( ) ;
} ,
2017-12-05 10:46:53 +00:00
2018-06-15 14:25:05 +01:00
load ( ) {
this . get ( 'categoryService' ) . getDocumentCategories ( this . get ( 'document.id' ) ) . then ( ( selected ) => {
this . set ( 'selectedCategories' , selected ) ;
} ) ;
2017-12-05 10:46:53 +00:00
2018-06-15 14:25:05 +01:00
let tagz = [ ] ;
if ( ! _ . isUndefined ( this . get ( 'document.tags' ) ) && this . get ( 'document.tags' ) . length > 1 ) {
let tags = this . get ( 'document.tags' ) . split ( '#' ) ;
2017-12-05 10:46:53 +00:00
_ . each ( tags , function ( tag ) {
2018-06-15 14:25:05 +01:00
if ( tag . length > 0 ) {
tagz . pushObject ( tag ) ;
}
} ) ;
}
2018-01-22 10:31:03 +00:00
2018-06-15 14:25:05 +01:00
this . set ( 'tagz' , A ( tagz ) ) ;
} ,
2017-12-05 10:46:53 +00:00
2018-06-15 14:25:05 +01:00
actions : {
onSelectVersion ( version ) {
let space = this . get ( 'folder' ) ;
2017-12-05 10:46:53 +00:00
2018-06-15 14:25:05 +01:00
this . get ( 'router' ) . transitionTo ( 'document' ,
space . get ( 'id' ) , space . get ( 'slug' ) ,
version . documentId , this . get ( 'document.slug' ) ) ;
2018-06-25 19:43:29 +01:00
} ,
onEditLifecycle ( ) {
//no op
} ,
onEditProtection ( ) {
//no op
} ,
onEditCategory ( ) {
if ( ! this . get ( 'permissions.spaceManage' ) ) return ;
this . get ( 'router' ) . transitionTo ( 'document.settings' , { queryParams : { tab : 'meta' } } ) ;
2018-01-22 10:31:03 +00:00
}
2017-12-05 10:46:53 +00:00
}
2017-09-21 15:48:00 +01:00
} ) ;