@@ -65,7 +65,8 @@ import {
6565 LOAD_PROJECT_MEMBER_INVITES ,
6666 CREATE_PROJECT_PHASE_TIMELINE_MILESTONES ,
6767 LOAD_PROJECT_MEMBER ,
68- ES_REINDEX_DELAY
68+ ES_REINDEX_DELAY ,
69+ CREATE_PROJECT_PHASE
6970} from '../../config/constants'
7071import {
7172 updateProductMilestone ,
@@ -178,6 +179,7 @@ function getProjectPhasesWithProducts(projectId) {
178179 'endDate' ,
179180 'id' ,
180181 'name' ,
182+ 'description' ,
181183 'progress' ,
182184 'projectId' ,
183185 'spentBudget' ,
@@ -273,16 +275,20 @@ function createProductsTimelineAndMilestone(project) {
273275/**
274276 * Create phase and product for the project
275277 *
276- * @param {Object } project project
277- * @param {Object } productTemplate product template
278- * @param {String } status (optional) project/phase status
278+ * @param {Object } project project
279+ * @param {Object } productTemplate product template
280+ * @param {String } status (optional) project/phase status
281+ * @param {Date } startDate start date of the phase
282+ * @param {Date } endDate end date of the phase
283+ * @param {Boolean } createTimeline flag to indicate if we need to create timeline for the phase
279284 *
280285 * @return {Promise } project
281286 */
282- export function createProjectPhaseAndProduct ( project , productTemplate , status = PHASE_STATUS_DRAFT , startDate , endDate ) {
287+ export function createProjectPhaseAndProduct ( project , productTemplate , status = PHASE_STATUS_DRAFT , startDate , endDate , createTimeline = true ) {
283288 const param = {
284289 status,
285290 name : productTemplate . name ,
291+ description : productTemplate . description ,
286292 productTemplateId : productTemplate . id
287293 }
288294 if ( startDate ) {
@@ -293,13 +299,21 @@ export function createProjectPhaseAndProduct(project, productTemplate, status =
293299 }
294300
295301 return createProjectPhase ( project . id , param ) . then ( ( phase ) => {
296- // we also wait until timeline is created as we will load it for the phase after creation
297- return createTimelineAndMilestoneForProduct ( phase . products [ 0 ] , phase ) . then ( ( timeline ) => ( {
298- project,
299- phase,
300- product :phase . products [ 0 ] ,
301- timeline,
302- } ) )
302+ if ( createTimeline ) {
303+ // we also wait until timeline is created as we will load it for the phase after creation
304+ return createTimelineAndMilestoneForProduct ( phase . products [ 0 ] , phase ) . then ( ( timeline ) => ( {
305+ project,
306+ phase,
307+ product :phase . products [ 0 ] ,
308+ timeline,
309+ } ) )
310+ } else {
311+ return Promise . resolve ( {
312+ project,
313+ phase,
314+ product :phase . products [ 0 ]
315+ } )
316+ }
303317 } )
304318}
305319
@@ -331,6 +345,25 @@ function createPhaseAndMilestonesRequest(project, productTemplate, status = PHAS
331345 } )
332346}
333347
348+ /**
349+ * Creates phase and product only, without timeline and milestone. Introduced with project plan simplification
350+ * work where we removed timeline and milestones for projects with version v4
351+ * @param {* } project
352+ * @param {* } productTemplate
353+ * @param {* } status
354+ * @param {* } startDate
355+ * @param {* } endDate
356+ */
357+ export function createPhaseWithoutTimeline ( project , productTemplate , status , startDate , endDate ) {
358+ return ( dispatch ) => {
359+ console . log ( CREATE_PROJECT_PHASE )
360+ return dispatch ( {
361+ type : CREATE_PROJECT_PHASE ,
362+ payload : createProjectPhaseAndProduct ( project , productTemplate , status , startDate , endDate , false )
363+ } )
364+ }
365+ }
366+
334367export function createPhaseAndMilestones ( project , productTemplate , status , startDate , endDate , milestones ) {
335368 return ( dispatch , getState ) => {
336369 return dispatch ( {
@@ -340,9 +373,6 @@ export function createPhaseAndMilestones(project, productTemplate, status, start
340373 const state = getState ( )
341374 const project = state . projectState . project
342375
343- console . log ( 'project.status' , project . status )
344- console . log ( 'status' , status )
345-
346376 // if phase is created as ACTIVE, move project to ACTIVE too
347377 if (
348378 _ . includes ( [ PROJECT_STATUS_DRAFT , PROJECT_STATUS_IN_REVIEW , PROJECT_STATUS_REVIEWED ] , project . status ) &&
@@ -464,6 +494,7 @@ export function updatePhase(projectId, phaseId, updatedProps, phaseIndex) {
464494 const phaseStartDate = timeline ? timeline . startDate : phase . startDate
465495 const startDateChanged = updatedProps . startDate ? updatedProps . startDate . diff ( phaseStartDate ) : null
466496 const phaseActivated = phaseStatusChanged && updatedProps . status === PHASE_STATUS_ACTIVE
497+ const projectVersion = state . projectState . project . version
467498
468499 if ( updatedProps . startDate ) {
469500 updatedProps . startDate = moment ( updatedProps . startDate ) . format ( 'YYYY-MM-DD' )
@@ -494,7 +525,7 @@ export function updatePhase(projectId, phaseId, updatedProps, phaseIndex) {
494525 // - phase's status is changed to active
495526 // - there is not active milestone alreay (this can happen when phase is made active more than once
496527 // e.g. Active => Paused => Active)
497- if ( timeline && ! activeMilestone && phaseActivated ) {
528+ if ( projectVersion !== 'v4' && timeline && ! activeMilestone && phaseActivated ) {
498529 dispatch (
499530 updateProductMilestone (
500531 productId ,
0 commit comments