Skip to content

Commit

Permalink
Merge pull request Dolibarr#7 from ATM-Consulting/new_split_dialog
Browse files Browse the repository at this point in the history
NEW : Split dialog for kanban card of type User story or Scrum task
  • Loading branch information
atm-gregr authored Jul 29, 2022
2 parents c7115fc + a5e9ded commit 1c3bc9c
Show file tree
Hide file tree
Showing 12 changed files with 1,117 additions and 75 deletions.
4 changes: 3 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

## Version 0.1 [2020-12-25]
- NEW : Split dialog for kanban card of type User story or Scrum task *28/07/2022* - 1.1.0

## Version 1.0 [2020-12-25]

- FIX : Suppression des champs qté réalisée et quantité prévue à la création d'un sprint *21/07/2022* - 1.0.9
- FIX : Update visuel de la liste US planifiée *21/07/2022* - 1.0.8
Expand Down
26 changes: 25 additions & 1 deletion admin/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@

$formSetup = new FormSetup($db);


/*
* DEMO
// Hôte
$item = $formSetup->newItem('NO_PARAM_JUST_TEXT');
$item->fieldOverride = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'];
Expand Down Expand Up @@ -127,6 +128,11 @@
$formSetup->newItem('Title')->setAsTitle();
// Setup conf MYMODULE_MYPARAM8
$item = $formSetup->newItem('MYMODULE_MYPARAM8');
$TField = array(
Expand Down Expand Up @@ -157,6 +163,24 @@
//$item->fieldOverride = false; // set this var to override field output will override $fieldInputOverride and $fieldOutputOverride too
//$item->fieldInputOverride = false; // set this var to override field input
//$item->fieldOutputOverride = false; // set this var to override field output
*/


$item = $formSetup->newItem('SP_MAX_SCRUM_TASK_STEP_QTY');
$item->fieldAttr = array(
'type' => 'number',
'step' => '0.01',
'min' => 0
);

$item = $formSetup->newItem('SP_MAX_SCRUM_TASK_MAX_QTY');
$item->fieldAttr = array(
'type' => 'number',
'step' => getDolGlobalString('SP_MAX_SCRUM_TASK_STEP_QTY'),
'min' => 0
);

$formSetup->htmlAfterOutputForm.='<script>$(document).on("change", "#setup-SP_MAX_SCRUM_TASK_STEP_QTY", function(){$("#setup-SP_MAX_SCRUM_TASK_MAX_QTY").attr("step", $(this).val());});</script>';


$setupnotempty =+ count($formSetup->items);
Expand Down
67 changes: 67 additions & 0 deletions class/scrumcard.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@ public function getNextNumRef()
public function getScrumKanBanItemObjectFormatted(){
global $user;

// TODO : voir si $object peut être factorisé avec getScrumKanBanItemObjectStd mais attention il doit être compatible avec l'objet js des items de kanban
$object = new stdClass();
$object->id = 'scrumcard-' . $this->id; // kanban dom id

Expand Down Expand Up @@ -1098,6 +1099,56 @@ public function getScrumKanBanItemObjectFormatted(){
}


/**
* get this object formatted for ajax ans json
* @return stdClass
*/
public function getScrumKanBanItemObjectStd(){


$object = new stdClass();
$object->objectId = $this->id;
$object->type = 'scrum-card';// le type dans le kanban tel que getScrumKanBanItemObjectFormatted le fait
$object->id = 'scrumcard-' . $this->id; // kanban dom id
$object->label = $this->label;
$object->element = $this->element;
$object->cardUrl = dol_buildpath('/scrumproject/scrumcard_card.php',1).'?id='.$this->id;
$object->title = '';
$object->status = intval($this->status);
$object->statusLabel = $this->LibStatut(intval($this->status), 1);
$object->contactUsersAffected = $this->liste_contact(-1,'internal',1);

/**
* Traitement de l'élément attaché
*/

$object->targetelementid = $this->fk_element;
$object->targetelement = $this->element_type;

$res = $this->fetchElementObject();
if($res){
$object->elementObject = false;
if(is_callable(array($this->elementObject, 'getScrumKanBanItemObjectStd'))){
$object->elementObject = $this->elementObject->getScrumKanBanItemObjectStd($this, $object);
}

// Si gestion de l'object sans getScrumKanBanItemObjectStd : **typiquement les objects Dolibarr**
if(!$object->elementObject){
$object->elementObject = new stdClass();
$object->elementObject->contactUsersAffected = $this->elementObject->liste_contact(-1,'internal', 1);

if($this->elementObject->element == 'project_task'){
$object->type = 'project-task';
}else{
$object->type = 'scrum-card-linked';
}
}
}

return $object;
}



/**
* Return HTML string to put an input field into a page
Expand Down Expand Up @@ -1392,4 +1443,20 @@ public static function getInternalContactIdFromCode($code, $object, &$error = ''
}
}

/**
* Permet de spliter la carte en 2
* @param double $qty la quantité de la nouvelle carte
* @param string $newCardLabel le libelle de la nouvelle carte
* @return void
*/
public function splitCard($qty, $newCardLabel, User $user){
$this->fetchElementObject();
if(is_callable(array($this->elementObject, 'splitCard'))){
return $this->elementObject->splitCard( $qty, $newCardLabel, $this, $user);
}else{
$this->error = 'splitCard not supported';
return false;
}
}

}
116 changes: 116 additions & 0 deletions class/scrumtask.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,40 @@ public function getProjectTaskTimeLinkId($fk_project_task_time){
return false;
}


/**
* get this object formatted for ajax ans json
* @return stdClass
*/
public function getScrumKanBanItemObjectStd(){


$object = new stdClass();
$object->objectId = $this->id;
$object->ref= $this->ref;
$object->type = 'scrum-user-story-task';// le type dans le kanban tel que getScrumKanBanItemObjectFormatted le fait
$object->label = $this->label;
$object->element = $this->element;
$object->cardUrl = dol_buildpath('/scrumproject/scrumtask_card.php',1).'?id='.$this->id;
$object->status = intval($this->status);
$object->statusLabel = $this->LibStatut(intval($this->status), 1);
$object->contactUsersAffected = $this->liste_contact(-1,'internal',1);

$object->fk_scrum_user_story_sprint = $this->fk_scrum_user_story_sprint;
$object->fk_scrum_user_story_sprint = $this->fk_scrum_user_story_sprint;
$object->qty_planned = doubleval($this->qty_planned);
$object->qty_consumed = doubleval($this->qty_consumed);

$object->qty_remain_for_split = 0;
if($this->qty_planned - $this->qty_consumed > 0){
$object->qty_remain_for_split = $this->qty_planned - $this->qty_consumed;
}

return $object;
}



/**
* @param $msg
* @return void
Expand All @@ -1270,4 +1304,86 @@ public function setErrorMsg($msg){
$this->errors[] = $msg;
}
}


/**
* Permet de spliter la carte en 2
* @param double $qty la quantité de la nouvelle carte
* @param string $newCardLabel le libelle de la nouvelle carte
* @param ScrumCard $scrumCard
* @return bool
*/
public function splitCard($qty, $newCardLabel, ScrumCard $scrumCard, User $user ){

if(!class_exists('ScrumTask')){
require_once __DIR__ . '/scrumtask.class.php';
}
if(!class_exists('ScrumCard')){
require_once __DIR__ . '/scrumcard.class.php';
}

$qty = doubleval($qty);

$this->calcTimeSpent();

// Vérification de la liaison entre ScrumCard et ScrumTask
if($scrumCard->element_type != $this->element || $scrumCard->fk_element != $this->id ){
$this->error = 'Error : scrum card not linked';
$this->errors[] = $this->error;
return false;
}


// Vérification du temps restant
if($qty > $this->qty_planned - $this->qty_consumed ){
$this->error = 'Too much quantity';
$this->errors[] = $this->error;
return false;
}

// Ajout de la nouvelle ScrumTask
$newScrumTask = new ScrumTask($this->db);
$newScrumTask->fk_scrum_user_story_sprint = $this->fk_scrum_user_story_sprint;
$newScrumTask->description = $this->description;

$newScrumTask->qty_planned = $qty;
$newScrumTask->label = $newCardLabel;
if(empty($newCardLabel) || is_array($newCardLabel)){ $newScrumTask->label = $this->label;}

$resCreate = $newScrumTask->create($user);
if($resCreate<0){
$this->error = $newScrumTask->error;
$this->errors = array_merge($this->errors, $newScrumTask->errors);
return false;
}

// MISE A JOUR DE LA SCRUM TASK QUE L'ON SPLIT
$this->qty_planned-= $qty;
$resUpdate = $this->update($user);
if($resUpdate<1){
$this->error = 'Error updating ScrumTask : '.$this->error;
$this->errors = array_merge($this->errors, $this->errors);
return false;
}

// Bloc deja effectué par $newScrumTask->create
// // AJOUT DE LA CARD LIÉE
// $newScrumCard = new ScrumCard($this->db);
// if(empty($newCardLabel)){
// $newScrumCard->label = $this->label;
// }
// $newScrumCard->label = $newScrumTask->label;
// $newScrumCard->fk_element = $newScrumTask->id;
// $newScrumCard->element_type = $newScrumTask->element;
// $newScrumCard->fk_scrum_kanbanlist = $scrumCard->fk_scrum_kanbanlist;
// $newScrumCard->fk_rank = $scrumCard->fk_rank;
// $res = $newScrumCard->create($user);
// if($res<=0){
// $this->error = 'Error creating ScrumCard : '.$newScrumCard->error;
// $this->errors = array_merge($this->errors, $newScrumCard->errors);
// return false;
// }

return true;
}
}
Loading

0 comments on commit 1c3bc9c

Please sign in to comment.