diff --git a/api/v1/entries/bug.php b/api/v1/entries/bug.php index 4cb6cc5b6e..2e79f9889a 100644 --- a/api/v1/entries/bug.php +++ b/api/v1/entries/bug.php @@ -9,7 +9,7 @@ * @version 1 * @link http://www.zentao.net */ -class bugEntry extends entry +class bugEntry extends entry { /** * GET method. @@ -24,7 +24,73 @@ class bugEntry extends entry $control->view($bugID); $data = $this->getData(); - $bug = $data->data->bug; + + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); + + $bug = $data->data->bug; + + /* Set product name */ + $bug->productName = $data->data->product->name; + + /* Set module title */ + $moduleTitle = ''; + if(empty($bug->module)) $moduleTitle = '/'; + if($bug->module) + { + $modulePath = $data->data->modulePath; + foreach($modulePath as $key => $module) + { + $moduleTitle .= $module->name; + if(isset($modulePath[$key + 1])) $moduleTitle .= '/'; + } + } + $bug->moduleTitle = $moduleTitle; + + if($bug->openedBy) $bug->openedBy = $this->formatUser($bug->openedBy, $data->data->users); + if($bug->resolvedBy) $bug->resolvedBy = $this->formatUser($bug->resolvedBy, $data->data->users); + if($bug->closedBy) $bug->closedBy = $this->formatUser($bug->closedBy, $data->data->users); + if($bug->lastEditedBy) $bug->lastEditedBy = $this->formatUser($bug->lastEditedBy, $data->data->users); + if($bug->assignedTo) + { + $usersWithAvatar = $this->loadModel('user')->getListByAccounts(array($bug->assignedTo), 'account'); + $bug->assignedTo = zget($usersWithAvatar, $bug->assignedTo); + } + + $mailto = array(); + if($bug->mailto) + { + foreach(explode(',', $bug->mailto) as $account) + { + if(empty($account)) continue; + $mailto[] = $this->formatUser($account, $data->data->users); + } + } + $bug->mailto = $mailto; + + $openedBuilds = array(); + foreach(explode(',', $bug->openedBuild) as $buildID) + { + if(empty($buildID)) continue; + + $openedBuild = new stdclass(); + $openedBuild->id = $buildID; + $openedBuild->title = zget($data->data->builds, $buildID, ''); + + $openedBuilds[] = $openedBuild; + } + $bug->openedBuild = $openedBuilds; + + if($bug->resolvedBuild) + { + $resolvedBuild = new stdclass(); + $resolvedBuild->id = $bug->resolvedBuild; + $resolvedBuild->title = zget($data->data->builds, $bug->resolvedBuild, ''); + $bug->resolvedBuild = $resolvedBuild; + } + + $bug->actions = $this->loadModel('action')->processActionForAPI($data->data->actions, $data->data->users, $this->lang->bug); + $this->send(200, $this->format($bug, 'activatedDate:time,openedDate:time,assignedDate:time,resolvedDate:time,closedDate:time,lastEditedDate:time,deadline:date,deleted:bool')); } diff --git a/api/v1/entries/bugs.php b/api/v1/entries/bugs.php index e0fec1d8b6..e155510712 100644 --- a/api/v1/entries/bugs.php +++ b/api/v1/entries/bugs.php @@ -24,7 +24,7 @@ class bugsEntry extends entry if(empty($productID)) return $this->sendError(400, 'Need product id.'); $control = $this->loadController('bug', 'browse'); - $control->browse($productID, $this->param('branch', ''), $this->param('status', 'unclosed'), 0, $this->param('order', 'id_desc'), 0, $this->param('limit', 20), $this->param('page', 1)); + $control->browse($productID, $this->param('branch', 'all'), $this->param('status', ''), 0, $this->param('order', 'id_desc'), 0, $this->param('limit', 20), $this->param('page', 1)); $data = $this->getData(); @@ -59,7 +59,7 @@ class bugsEntry extends entry return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'bugs' => array_values($result))); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } diff --git a/api/v1/entries/build.php b/api/v1/entries/build.php index 68eef04ea9..3d840c6855 100644 --- a/api/v1/entries/build.php +++ b/api/v1/entries/build.php @@ -27,10 +27,7 @@ class buildEntry extends Entry if(isset($data->status) and $data->status == 'success') return $this->send(200, $this->format($data->data->build, 'stories:idList,bugs:idList,deleted:bool')); /* Exception handling. */ - if(isset($data->status) and $data->status == 'fail') - { - return isset($data->code) and $data->code == 404 ? $this->send404() : $this->sendError(400, $data->message); - } + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $this->sendError(400, 'error'); } diff --git a/api/v1/entries/builds.php b/api/v1/entries/builds.php index 4ffa3eb258..fff692e506 100644 --- a/api/v1/entries/builds.php +++ b/api/v1/entries/builds.php @@ -28,15 +28,12 @@ class buildsEntry extends entry $data = $this->getData(); if(!isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $result = array(); foreach($data->data->projectBuilds as $productID => $builds) { - foreach($builds as $build) - { - $result[] = $this->format($build, 'bugs:idList,stories:idList,deleted:bool'); - } + foreach($builds as $build) $result[] = $this->format($build, 'bugs:idList,stories:idList,deleted:bool'); } return $this->send(200, array('total' => count($result), 'builds' => $result)); diff --git a/api/v1/entries/doc.php b/api/v1/entries/doc.php new file mode 100644 index 0000000000..7be2c0d40b --- /dev/null +++ b/api/v1/entries/doc.php @@ -0,0 +1,89 @@ + + * @package entries + * @version 1 + * @link http://www.zentao.net + */ +class docEntry extends entry +{ + /** + * GET method. + * + * @param int $docID + * @access public + * @return void + */ + public function get($docID) + { + $control = $this->loadController('doc', 'view'); + $control->view($docID); + + $data = $this->getData(); + + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); + + $doc = $data->data->doc; + + unset($doc->draft); + if(!empty($doc->files)) $doc->files = array_values((array)$doc->files); + + /* Set lib name */ + $doc->libName = $data->data->lib->name; + + /* Format user for api. */ + if($doc->editedBy) $doc->editedBy = $this->formatUser($doc->editedBy, $data->data->users); + if($doc->addedBy) + { + $usersWithAvatar = $this->loadModel('user')->getListByAccounts(array($doc->addedBy), 'account'); + $doc->addedBy = zget($usersWithAvatar, $doc->addedBy); + } + + $this->send(200, $this->format($doc, 'addedDate:time,assignedDate:date,editedDate:time')); + } + + /** + * PUT method. + * + * @param int $storyID + * @access public + * @return void + */ + public function put($storyID) + { + $oldStory = $this->loadModel('story')->getByID($storyID); + + /* Set $_POST variables. */ + $fields = 'type'; + $this->batchSetPost($fields, $oldStory); + $this->setPost('parent', 0); + + $control = $this->loadController('story', 'edit'); + $control->edit($storyID); + + $this->getData(); + $story = $this->story->getByID($storyID); + $this->sendSuccess(200, $this->format($story, 'openedDate:time,assignedDate:time,reviewedDate:time,lastEditedDate:time,closedDate:time,deleted:bool')); + } + + /** + * DELETE method. + * + * @param int $storyID + * @access public + * @return void + */ + public function delete($storyID) + { + $control = $this->loadController('story', 'delete'); + $control->delete($storyID, 'yes'); + + $this->getData(); + $this->sendSuccess(200, 'success'); + } +} diff --git a/api/v1/entries/execution.php b/api/v1/entries/execution.php index 260cdafc78..d002881789 100644 --- a/api/v1/entries/execution.php +++ b/api/v1/entries/execution.php @@ -27,7 +27,7 @@ class executionEntry extends Entry $data = $this->getData(); if(!$data or !isset($data->status)) return $this->send400('error'); - if(isset($data->status) and $data->status == 'fail') return isset($data->code) and $data->code == 404 ? $this->send404() : $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $execution = $this->format($data->data->execution, 'openedDate:time,lastEditedDate:time,closedDate:time,canceledDate:time,begin:date,end:date,realBegan:date,realEnd:date,deleted:bool'); diff --git a/api/v1/entries/executionbugs.php b/api/v1/entries/executionbugs.php index 786fe343ef..0a47390a56 100644 --- a/api/v1/entries/executionbugs.php +++ b/api/v1/entries/executionbugs.php @@ -59,7 +59,7 @@ class executionBugsEntry extends entry return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'bugs' => array_values($result))); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } diff --git a/api/v1/entries/executionbuilds.php b/api/v1/entries/executionbuilds.php new file mode 100644 index 0000000000..b6285739b9 --- /dev/null +++ b/api/v1/entries/executionbuilds.php @@ -0,0 +1,41 @@ + + * @package entries + * @version 1 + * @link http://www.zentao.net + */ +class executionBuildsEntry extends entry +{ + /** + * GET method. + * + * @param int $executionID + * @access public + * @return void + */ + public function get($executionID = 0) + { + if(empty($executionID)) $executionID = $this->param('execution', 0); + if(empty($executionID)) return $this->sendError(400, "Need execution id."); + + $control = $this->loadController('execution', 'build'); + $control->build($executionID, $this->param('status', 'all'), $this->param('param', 0), $this->param('order', 't1.date_desc,t1.id_desc')); + $data = $this->getData(); + + if(!isset($data->status)) return $this->sendError(400, 'error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); + + $result = array(); + foreach($data->data->executionBuilds as $builds) + { + foreach($builds as $build) $result[] = $this->format($build, 'bugs:idList,stories:idList,deleted:bool'); + } + + return $this->send(200, array('total' => count($result), 'builds' => $result)); + } +} diff --git a/api/v1/entries/executioncases.php b/api/v1/entries/executioncases.php index f0431fb2a6..fbdd958a41 100644 --- a/api/v1/entries/executioncases.php +++ b/api/v1/entries/executioncases.php @@ -42,7 +42,7 @@ class executionCasesEntry extends entry return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'cases' => $result)); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } diff --git a/api/v1/entries/executions.php b/api/v1/entries/executions.php index 507076dabb..89b8f22278 100644 --- a/api/v1/entries/executions.php +++ b/api/v1/entries/executions.php @@ -32,7 +32,7 @@ class executionsEntry extends entry /* Response */ $data = $this->getData(); if(!$data or !isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $executions = $data->data->executionStats; $pager = $data->data->pager; @@ -84,15 +84,17 @@ class executionsEntry extends entry $this->batchSetPost($fields); $projectID = $this->param('project', $projectID); - $this->setPost('project', $projectID); - $this->setPost('acl', $this->request('acl', 'private')); + $this->setPost('project', $projectID); + $this->setPost('acl', $this->request('acl', 'private')); + $this->setPost('PO', $this->request('PO', '')); + $this->setPost('PM', $this->request('PM', '')); + $this->setPost('QD', $this->request('QD', '')); + $this->setPost('RD', $this->request('RD', '')); $this->setPost('whitelist', $this->request('whitelist', array())); - $this->setPost('products', $this->request('products', array())); - $this->setPost('plans', $this->request('plans', array())); - - $control = $this->loadController('execution', 'create'); - $this->requireFields('name,code,begin,end,days'); + $this->setPost('products', $this->request('products', array())); + $this->setPost('plans', $this->request('plans', array())); + $control = $this->loadController('execution', 'create'); $this->requireFields('name,code,begin,end,days'); $control->create($projectID); $data = $this->getData(); diff --git a/api/v1/entries/executionstories.php b/api/v1/entries/executionstories.php index 54a1f971e4..d20a842042 100644 --- a/api/v1/entries/executionstories.php +++ b/api/v1/entries/executionstories.php @@ -39,7 +39,7 @@ class executionStoriesEntry extends entry return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'stories' => $result)); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } diff --git a/api/v1/entries/file.php b/api/v1/entries/file.php index b69ed0539d..833739c02a 100644 --- a/api/v1/entries/file.php +++ b/api/v1/entries/file.php @@ -11,6 +11,23 @@ */ class fileEntry extends Entry { + /** + * GET method. + * + * @access public + * @return void + */ + public function get($fileID) + { + $control = $this->loadController('file', 'download'); + $control->download($fileID); + + $data = $this->getData(); + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); + + $this->send(200, $data); + } /** * PUT method. * diff --git a/api/v1/entries/files.php b/api/v1/entries/files.php index 17faf9f28f..0783362176 100644 --- a/api/v1/entries/files.php +++ b/api/v1/entries/files.php @@ -27,10 +27,7 @@ class filesEntry extends Entry $data = $this->getData(); if(!$data or !isset($data->status)) return $this->send400('error'); - if(isset($data->status) and $data->status == 'error') - { - return isset($data->code) and $data->code == 404 ? $this->send404() : $this->sendError(400, $data->message); - } + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $this->send(200, array('id' => $data->id)); } diff --git a/api/v1/entries/issue.php b/api/v1/entries/issue.php index d5a4cc0825..211b43a1b5 100644 --- a/api/v1/entries/issue.php +++ b/api/v1/entries/issue.php @@ -30,7 +30,7 @@ class issueEntry extends Entry $data = $this->getData(); if(!$data or (isset($data->message) and $data->message == '404 Not found')) return $this->send404(); if(isset($data->status) and $data->status == 'success') return $this->send(200, $this->format($data->data->issue, 'createdDate:time,editedDate:time,assignedDate:time')); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $this->sendError(400, 'error'); } diff --git a/api/v1/entries/issues.php b/api/v1/entries/issues.php index a387c246b1..444dc2e0b5 100644 --- a/api/v1/entries/issues.php +++ b/api/v1/entries/issues.php @@ -28,7 +28,7 @@ class issuesEntry extends entry $data = $this->getData(); if(!isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $pager = $data->data->pager; $result = array(); diff --git a/api/v1/entries/meetings.php b/api/v1/entries/meetings.php index 8f077f0852..6466ded6a0 100644 --- a/api/v1/entries/meetings.php +++ b/api/v1/entries/meetings.php @@ -32,7 +32,7 @@ class meetingsEntry extends entry $data = $this->getData(); if(!isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $pager = $data->data->pager; $result = array(); diff --git a/api/v1/entries/product.php b/api/v1/entries/product.php index e22c2d34ba..80c03aed25 100644 --- a/api/v1/entries/product.php +++ b/api/v1/entries/product.php @@ -27,13 +27,13 @@ class productEntry extends Entry $data = $this->getData(); if(!$data or !isset($data->status)) return $this->send400('error'); - if(isset($data->status) and $data->status == 'fail') - { - return isset($data->code) and $data->code == 404 ? $this->send404() : $this->sendError(400, $data->message); - } + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $product = $this->format($data->data->product, 'createdDate:time'); + $this->loadModel('testcase'); + $product->caseReview = ($this->config->testcase->needReview or !empty($this->config->testcase->forceReview)); + $users = $data->data->users; $product->PO = $this->formatUser($product->PO, $users); $product->QD = $this->formatUser($product->QD, $users); @@ -108,7 +108,7 @@ class productEntry extends Entry if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message); $product = $this->product->getByID($productID); - $this->send(200, array('product' => $this->format($product, 'createdDate:time'))); + $this->send(200, $this->format($product, 'createdDate:time')); } /** diff --git a/api/v1/entries/productplan.php b/api/v1/entries/productplan.php index 3df13abe58..ab10d35d26 100644 --- a/api/v1/entries/productplan.php +++ b/api/v1/entries/productplan.php @@ -27,10 +27,7 @@ class productplanEntry extends Entry $data = $this->getData(); if(!$data or !isset($data->status)) return $this->send400('error'); - if(isset($data->status) and $data->status == 'fail') - { - return isset($data->code) and $data->code == 404 ? $this->send404() : $this->sendError(400, $data->message); - } + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $plan = $this->format($data->data->plan, 'begin:date,end:date,deleted:bool'); diff --git a/api/v1/entries/productplans.php b/api/v1/entries/productplans.php index ea7ddbdbfd..e2f0296c32 100644 --- a/api/v1/entries/productplans.php +++ b/api/v1/entries/productplans.php @@ -33,12 +33,27 @@ class productplansEntry extends entry $result = array(); $plans = $data->data->plans; $pager = $data->data->pager; - foreach($plans as $plan) $result[] = $plan; + + foreach($plans as $plan) + { + if($plan->parent > 0 and isset($result[$plan->parent])) + { + $parentPlan = $result[$plan->parent]; + + if(!isset($parentPlan->children) or !is_array($parentPlan->children)) $parentPlan->children = array(); + $parentPlan->children[] = $plan; + $result[$plan->parent] = $parentPlan; + } + else + { + $result[$plan->id] = $plan; + } + } return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'plans' => array_values($result))); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } diff --git a/api/v1/entries/productprojects.php b/api/v1/entries/productprojects.php index 6af80adba3..8826d1a5bd 100644 --- a/api/v1/entries/productprojects.php +++ b/api/v1/entries/productprojects.php @@ -49,7 +49,7 @@ class productProjectsEntry extends entry return $this->send(200, $data); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); // TODO There is no handle for 401. return $this->sendError(400, 'error'); diff --git a/api/v1/entries/products.php b/api/v1/entries/products.php index aad54b2939..1d86cd3410 100644 --- a/api/v1/entries/products.php +++ b/api/v1/entries/products.php @@ -34,7 +34,7 @@ class productsEntry extends entry /* Response */ $data = $this->getData(); if(!$data or !isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $products = $data->data->products; @@ -113,7 +113,7 @@ class productsEntry extends entry $control->create($this->request('program', 0)); $data = $this->getData(); - if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); /* Response */ $product = $this->loadModel('product')->getByID($data->id); @@ -134,7 +134,7 @@ class productsEntry extends entry $control->ajaxGetDropMenu($this->request('productID', 0), $this->request('module', 'product'), $this->request('method', 'browse'), $this->request('extra', ''), $this->request('from', '')); $data = $this->getData(); - if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $dropMenu = array('owner' => array(), 'other' => array(), 'closed' => array()); foreach($data->data->products as $programID => $products) diff --git a/api/v1/entries/program.php b/api/v1/entries/program.php index 17a023d90b..9a5d873219 100644 --- a/api/v1/entries/program.php +++ b/api/v1/entries/program.php @@ -11,4 +11,60 @@ */ class programEntry extends Entry { + /** + * GET method. + * + * @param int $programID + * @access public + * @return void + */ + public function get($programID) + { + $program = $this->loadModel('program')->getByID($programID); + if(!$program) return $this->send404(); + + $this->send(200, $this->format($program, 'openedDate:time,realBegan:date,realEnd:date,deleted:bool')); + } + + /** + * PUT method. + * + * @param int $programID + * @access public + * @return void + */ + public function put($programID) + { + $oldProgram = $this->loadModel('program')->getByID($programID); + + /* Set $_POST variables. */ + $fields = 'name,PM,budget,budgetUnit,desc,parent,begin,end,realBegan,realEnd,acl,whitelist'; + $this->batchSetPost($fields, $oldProgram); + $this->setPost('parent', $this->request('parent', 0)); + + $control = $this->loadController('program', 'edit'); + $control->edit($programID); + + $this->getData(); + $program = $this->program->getByID($programID); + $this->send(200, $this->format($program, 'openedDate:time')); + } + + /** + * DELETE method. + * + * @param int $programID + * @access public + * @return void + */ + public function delete($programID) + { + $control = $this->loadController('program', 'delete'); + $control->delete(0, $programID, 'true'); + + $data = $this->getData(); + if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message); + + $this->sendSuccess(200, 'success'); + } } diff --git a/api/v1/entries/programs.php b/api/v1/entries/programs.php index 28989e0af5..78b6905445 100644 --- a/api/v1/entries/programs.php +++ b/api/v1/entries/programs.php @@ -30,7 +30,7 @@ class programsEntry extends Entry $data = $this->getData(); if(!$data or !isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $programs = $data->data->programs; $progressList = $data->data->progressList; @@ -72,6 +72,31 @@ class programsEntry extends Entry return $this->send(200, array('programs' => array_values($result))); } + /** + * POST method. + * + * @access public + * @return void + */ + public function post() + { + $fields = 'name,PM,budget,budgetUnit,desc,begin,end'; + $this->batchSetPost($fields); + $this->setPost('acl', $this->request('acl', 'open')); + $this->setPost('whitelist', $this->request('whitelist', array())); + + $control = $this->loadController('program', 'create'); + $this->requireFields('name,begin,end'); + + $control->create($this->request('parent', 0)); + + $data = $this->getData(); + if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message); + + $program = $this->loadModel('program')->getByID($data->id); + $this->send(201, $this->format($program, 'openedDate:time,whitelist:stringList')); + } + /** * Get drop menu. * @@ -80,7 +105,6 @@ class programsEntry extends Entry */ public function getDropMenu() { - $programs = $this->dao->select('id,name,parent,path,grade,`order`')->from(TABLE_PROJECT) ->where('deleted')->eq('0') ->andWhere('type')->eq('program') diff --git a/api/v1/entries/project.php b/api/v1/entries/project.php index 6d77705f02..f17cdde548 100644 --- a/api/v1/entries/project.php +++ b/api/v1/entries/project.php @@ -28,7 +28,7 @@ class projectEntry extends entry $data = $this->getData(); if(!$data or !isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $project = $this->format($data->data->project, 'begin:date,end:date,realBegan:date,realEnd:date,openedDate:time,lastEditedDate:time,closedDate:time,canceledDate:time,deleted:bool'); @@ -114,7 +114,7 @@ class projectEntry extends entry $control->edit($projectID); $data = $this->getData(); - if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); if(!isset($data->result)) return $this->sendError(400, 'error'); $project = $this->project->getByID($projectID); diff --git a/api/v1/entries/projectbugs.php b/api/v1/entries/projectbugs.php index f799f78d12..c0fd1ce86e 100644 --- a/api/v1/entries/projectbugs.php +++ b/api/v1/entries/projectbugs.php @@ -59,7 +59,7 @@ class projectBugsEntry extends entry return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'bugs' => array_values($result))); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } diff --git a/api/v1/entries/projectcases.php b/api/v1/entries/projectcases.php index e459c8f7c7..efdbde7ba0 100644 --- a/api/v1/entries/projectcases.php +++ b/api/v1/entries/projectcases.php @@ -45,8 +45,7 @@ class projectCasesEntry extends entry return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'cases' => $result)); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); - + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } } diff --git a/api/v1/entries/projectreleases.php b/api/v1/entries/projectreleases.php index af02e042fb..15beeab941 100644 --- a/api/v1/entries/projectreleases.php +++ b/api/v1/entries/projectreleases.php @@ -37,8 +37,7 @@ class projectReleasesEntry extends entry return $this->send(200, array('total' => count($result), 'releases' => $result)); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); - + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } diff --git a/api/v1/entries/projects.php b/api/v1/entries/projects.php index ae68b4319d..9c55caff1d 100644 --- a/api/v1/entries/projects.php +++ b/api/v1/entries/projects.php @@ -64,9 +64,7 @@ class projectsEntry extends entry return $this->send(200, $data); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); - - // TODO There is no handle for 401. + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } @@ -99,7 +97,7 @@ class projectsEntry extends entry $project = $this->loadModel('project')->getByID($data->id); - $this->send(201, $this->format($project, 'openedDate:time,lastEditedDate:time,closedDate:time,canceledDate:time')); + $this->send(201, $this->format($project, 'openedDate:time,lastEditedDate:time,closedDate:time,canceledDate:time,budget:int')); } /** diff --git a/api/v1/entries/projectstories.php b/api/v1/entries/projectstories.php index b8be4683ab..e742871106 100644 --- a/api/v1/entries/projectstories.php +++ b/api/v1/entries/projectstories.php @@ -39,8 +39,7 @@ class projectStoriesEntry extends entry return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'stories' => $result)); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); - + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } } diff --git a/api/v1/entries/release.php b/api/v1/entries/release.php index bced77d10f..41ab4c6661 100644 --- a/api/v1/entries/release.php +++ b/api/v1/entries/release.php @@ -25,10 +25,7 @@ class releaseEntry extends Entry $data = $this->getData(); if(!$data or !isset($data->status)) return $this->send400('error'); - if(isset($data->status) and $data->status == 'fail') - { - return isset($data->code) and $data->code == 404 ? $this->send404() : $this->sendError(400, $data->message); - } + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $release = $this->format($data->data->release, 'date:date,deleted:bool'); diff --git a/api/v1/entries/releases.php b/api/v1/entries/releases.php index 688551ab67..a38c6be803 100644 --- a/api/v1/entries/releases.php +++ b/api/v1/entries/releases.php @@ -37,8 +37,7 @@ class releasesEntry extends entry return $this->send(200, array('total' => count($result), 'releases' => $result)); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); - + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } } diff --git a/api/v1/entries/risk.php b/api/v1/entries/risk.php index dc887f6b31..89ed1a1b2c 100644 --- a/api/v1/entries/risk.php +++ b/api/v1/entries/risk.php @@ -26,7 +26,7 @@ class riskEntry extends Entry $data = $this->getData(); if(!$data or (isset($data->message) and $data->message == '404 Not found')) return $this->send404(); if(isset($data->status) and $data->status == 'success') return $this->send(200, $this->format($data->data->risk, 'createdDate:time,editedDate:time')); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $this->sendError(400, 'error'); } diff --git a/api/v1/entries/risks.php b/api/v1/entries/risks.php index 92026fd104..a18ef97f88 100644 --- a/api/v1/entries/risks.php +++ b/api/v1/entries/risks.php @@ -39,7 +39,7 @@ class risksEntry extends entry } if(!isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $pager = $data->data->pager; $result = array(); diff --git a/api/v1/entries/stakeholders.php b/api/v1/entries/stakeholders.php index e67a3a2d30..fe57064421 100644 --- a/api/v1/entries/stakeholders.php +++ b/api/v1/entries/stakeholders.php @@ -55,9 +55,7 @@ class stakeholdersEntry extends entry return $this->send(200, $data); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); - - // TODO There is no handle for 401. + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } diff --git a/api/v1/entries/stories.php b/api/v1/entries/stories.php index 09e8182702..8966e29da6 100644 --- a/api/v1/entries/stories.php +++ b/api/v1/entries/stories.php @@ -28,7 +28,7 @@ class storiesEntry extends entry $data = $this->getData(); if(!$data or !isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $stories = $data->data->stories; $pager = $data->data->pager; @@ -68,7 +68,7 @@ class storiesEntry extends entry $control->create($productID); $data = $this->getData(); - if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); if(isset($data->result) and !isset($data->id)) return $this->sendError(400, $data->message); $story = $this->loadModel('story')->getByID($data->id); diff --git a/api/v1/entries/story.php b/api/v1/entries/story.php index f41f13b3bf..87b51ba6aa 100644 --- a/api/v1/entries/story.php +++ b/api/v1/entries/story.php @@ -23,8 +23,88 @@ class storyEntry extends Entry $control = $this->loadController('story', 'view'); $control->view($storyID); - $data = $this->getData(); + $data = $this->getData(); + + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); + $story = $data->data->story; + + if(!empty($story->children)) $story->children = array_values((array)$story->children); + if(isset($story->planTitle)) $story->planTitle = array_values((array)$story->planTitle); + if($story->parent > 0) $story->parentPri = $this->dao->select('pri')->from(TABLE_STORY)->where('id')->eq($story->parent)->fetch('pri'); + + /* Set product name */ + $story->productName = $data->data->product->name; + + /* Set module title */ + $moduleTitle = ''; + if(empty($story->module)) $moduleTitle = '/'; + if($story->module) + { + $modulePath = $data->data->modulePath; + foreach($modulePath as $key => $module) + { + $moduleTitle .= $module->name; + if(isset($modulePath[$key + 1])) $moduleTitle .= '/'; + } + } + $story->moduleTitle = $moduleTitle; + + /* Format user for api. */ + if($story->assignedTo) $story->assignedTo = $this->formatUser($story->assignedTo, $data->data->users); + if($story->closedBy) $story->closedBy = $this->formatUser($story->closedBy, $data->data->users); + if($story->lastEditedBy) $story->lastEditedBy = $this->formatUser($story->lastEditedBy, $data->data->users); + if($story->openedBy) + { + $usersWithAvatar = $this->loadModel('user')->getListByAccounts(array($story->openedBy), 'account'); + $story->openedBy = zget($usersWithAvatar, $story->openedBy); + } + + $mailto = array(); + if($story->mailto) + { + foreach(explode(',', $story->mailto) as $account) + { + if(empty($account)) continue; + $mailto[] = $this->formatUser($account, $data->data->users); + } + } + $story->mailto = $mailto; + + $reviewedBy = array(); + if($story->reviewer) + { + foreach($story->reviewer as $account) + { + if(empty($account)) continue; + $reviewedBy[] = $this->formatUser($account, $data->data->users); + } + } + $story->reviewedBy = $reviewedBy; + + $storyTasks = array(); + foreach($story->tasks as $executionTasks) + { + foreach($executionTasks as $task) + { + if(!isset($data->data->executions->{$task->execution})) continue; + $storyTasks[] = $this->filterFields($task, 'id,name,type'); + } + } + $story->tasks = $storyTasks; + + $story->bugs = array(); + foreach($data->data->bugs as $bug) $story->bugs[] = $this->filterFields($bug, 'id,title'); + + $story->cases = array(); + foreach($data->data->cases as $case) $story->cases[] = $this->filterFields($case, 'id,title'); + + $story->requirements = array(); + foreach($data->data->relations as $relation) $story->requirements[] = $this->filterFields($relation, 'id,title'); + + $story->actions = $this->loadModel('action')->processActionForAPI($data->data->actions, $data->data->users, $this->lang->story); + $this->send(200, $this->format($story, 'openedDate:time,assignedDate:time,reviewedDate:time,lastEditedDate:time,closedDate:time')); } @@ -49,7 +129,7 @@ class storyEntry extends Entry $this->getData(); $story = $this->story->getByID($storyID); - $this->sendSuccess(200, $this->format($story, 'openedDate:time,assignedDate:time,reviewedDate:time,lastEditedDate:time,closedDate:time,deleted:bool')); + $this->send(200, $this->format($story, 'openedDate:time,assignedDate:time,reviewedDate:time,lastEditedDate:time,closedDate:time,deleted:bool')); } /** diff --git a/api/v1/entries/storychange.php b/api/v1/entries/storychange.php index 4ae530c544..67f5102eb4 100644 --- a/api/v1/entries/storychange.php +++ b/api/v1/entries/storychange.php @@ -35,12 +35,13 @@ class storyChangeEntry extends Entry } $control = $this->loadController('story', 'change'); - $this->requireFields('title,spec'); + $this->requireFields('title,spec,verify'); $control->change($storyID); - + $data = $this->getData(); - if($data->status == 'fail') return $this->sendError(400, $data->message); + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $story = $this->loadModel('story')->getByID($storyID); diff --git a/api/v1/entries/task.php b/api/v1/entries/task.php index 651eb99457..a900057719 100644 --- a/api/v1/entries/task.php +++ b/api/v1/entries/task.php @@ -26,7 +26,7 @@ class taskEntry extends Entry $data = $this->getData(); if(!$data or !isset($data->status)) return $this->send400('error'); - if(isset($data->status) and $data->status == 'fail') return isset($data->code) and $data->code == 404 ? $this->send404() : $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $task = $data->data->task; @@ -38,6 +38,7 @@ class taskEntry extends Entry /* Set module title */ $moduleTitle = ''; + if(empty($task->module)) $moduleTitle = '/'; if($task->module) { $modulePath = $data->data->modulePath; @@ -84,7 +85,12 @@ class taskEntry extends Entry $user = zget($usersWithAvatar, $account, ''); $team->realname = $user ? $user->realname : $account; $team->avatar = $user ? $user->avatar : ''; - $team->progress = (empty($team->consumed) and empty($team->left)) ? 0 : round($team->consumed / ($team->consumed + $team->left) * 100, 1); + $team->estimate = round($team->estimate, 1); + $team->consumed = round($team->consumed, 1); + $team->left = round($team->left, 1); + + $allHours = $team->consumed + $team->left; + $team->progress = empty($allHours) ? 0 : round($team->consumed / $allHours * 100, 1); $teams[] = $team; } diff --git a/api/v1/entries/taskassignto.php b/api/v1/entries/taskassignto.php index ed6477fd8f..f97c8656ba 100644 --- a/api/v1/entries/taskassignto.php +++ b/api/v1/entries/taskassignto.php @@ -29,9 +29,10 @@ class taskAssignToEntry extends Entry $this->requireFields('assignedTo'); $control->assignTo($task->execution, $taskID); - + $data = $this->getData(); - if($data->result == 'fail') return $this->sendError(400, $data->message); + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $task = $this->loadModel('task')->getByID($taskID); diff --git a/api/v1/entries/taskfinish.php b/api/v1/entries/taskfinish.php index 80f20d20ce..28de8ae47e 100644 --- a/api/v1/entries/taskfinish.php +++ b/api/v1/entries/taskfinish.php @@ -34,9 +34,10 @@ class taskFinishEntry extends Entry $control = $this->loadController('task', 'finish'); $this->requireFields('assignedTo,currentConsumed,realStarted,finishedDate'); $control->finish($taskID); - + $data = $this->getData(); - if($data->result == 'fail') return $this->sendError(400, $data->message); + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $task = $this->loadModel('task')->getByID($taskID); diff --git a/api/v1/entries/tasks.php b/api/v1/entries/tasks.php index 7d657f275a..11f669385a 100644 --- a/api/v1/entries/tasks.php +++ b/api/v1/entries/tasks.php @@ -43,13 +43,12 @@ class tasksEntry extends entry foreach($tasks as $task) { if(isset($task->children)) $task->children = array_values((array)$task->children); - $result[] = $this->format($task, 'openedDate:time,assignedDate:time,realStarted:time,finishedDate:time,canceledDate:time,closedDate:time,lastEditedDate:time,deleted:bool'); + $result[] = $this->format($task, 'deadline:date,openedDate:time,assignedDate:time,realStarted:time,finishedDate:time,canceledDate:time,closedDate:time,lastEditedDate:time,deleted:bool'); } return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'tasks' => $result)); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); - + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } diff --git a/api/v1/entries/taskstart.php b/api/v1/entries/taskstart.php index d5896bf748..cf5adaee15 100644 --- a/api/v1/entries/taskstart.php +++ b/api/v1/entries/taskstart.php @@ -28,9 +28,10 @@ class taskStartEntry extends Entry $control = $this->loadController('task', 'start'); $this->requireFields('left'); $control->start($taskID); - + $data = $this->getData(); - if($data->result == 'fail') return $this->sendError(400, $data->message); + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $task = $this->loadModel('task')->getByID($taskID); diff --git a/api/v1/entries/testcase.php b/api/v1/entries/testcase.php index dd23826add..5e03cfc013 100644 --- a/api/v1/entries/testcase.php +++ b/api/v1/entries/testcase.php @@ -9,7 +9,7 @@ * @version 1 * @link http://www.zentao.net */ -class testcaseEntry extends entry +class testcaseEntry extends entry { /** * GET method. @@ -25,7 +25,7 @@ class testcaseEntry extends entry $data = $this->getData(); if(!$data or (isset($data->message) and $data->message == '404 Not found')) return $this->send404(); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); if(!isset($data->case)) $this->sendError(400, 'error'); $case = $data->case; diff --git a/api/v1/entries/testcases.php b/api/v1/entries/testcases.php index a5b67f2144..91e9ef788c 100644 --- a/api/v1/entries/testcases.php +++ b/api/v1/entries/testcases.php @@ -24,7 +24,7 @@ class testcasesEntry extends entry if(empty($productID)) return $this->sendError(400, 'Need product id.'); $control = $this->loadController('testcase', 'browse'); - $control->browse($productID, $this->param('branch', ''), $this->param('status', 'all'), 0, $this->param('order', 'id_desc'), 0, $this->param('limit', 20), $this->param('page', 1), $projectID); + $control->browse($productID, $this->param('branch', ''), $this->param('status', 'all'), 0, $this->param('order', 'id_desc'), 0, $this->param('limit', 20), $this->param('page', 1)); $data = $this->getData(); @@ -35,14 +35,14 @@ class testcasesEntry extends entry $result = array(); foreach($cases as $case) { + $case->status = array('code' => $case->status, 'name' => $this->lang->testcase->statusList[$case->status]); $result[] = $this->format($case, 'openedDate:time,lastEditedDate:time,lastRunDate:time,scriptedDate:date,reviewedDate:date,deleted:bool'); } return $this->send(200, array('page' => $pager->pageID, 'total' => $pager->recTotal, 'limit' => $pager->recPerPage, 'testcases' => $result)); } - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); - + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); return $this->sendError(400, 'error'); } diff --git a/api/v1/entries/testtask.php b/api/v1/entries/testtask.php index 42d6740e50..e28080fce3 100644 --- a/api/v1/entries/testtask.php +++ b/api/v1/entries/testtask.php @@ -9,7 +9,7 @@ * @version 1 * @link http://www.zentao.net */ -class testtaskEntry extends entry +class testtaskEntry extends entry { /** * GET method. @@ -24,7 +24,7 @@ class testtaskEntry extends entry $control->view($testtaskID); $data = $this->getData(); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); if(!isset($data->data->task)) $this->sendError(400, 'error'); $testtask = $data->data->task; diff --git a/api/v1/entries/testtasks.php b/api/v1/entries/testtasks.php index 155af3a789..67beb2b580 100644 --- a/api/v1/entries/testtasks.php +++ b/api/v1/entries/testtasks.php @@ -29,7 +29,7 @@ class testtasksEntry extends entry $data = $this->getData(); if(!isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $pager = $data->data->pager; $result = array(); diff --git a/api/v1/entries/todo.php b/api/v1/entries/todo.php index ff9f59a67b..466ca67b6c 100644 --- a/api/v1/entries/todo.php +++ b/api/v1/entries/todo.php @@ -9,7 +9,7 @@ * @version 1 * @link http://www.zentao.net */ -class todoEntry extends entry +class todoEntry extends entry { /** * GET method. @@ -25,7 +25,8 @@ class todoEntry extends entry $data = $this->getData(); if(!$data or (isset($data->message) and $data->message == '404 Not found')) return $this->send404(); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $todo = $data->data->todo; $this->send(200, $this->format($todo, 'assignedDate:time,finishedDate:time,closedDate:time')); @@ -45,7 +46,7 @@ class todoEntry extends entry /* Set $_POST variables. */ $fields = 'date,type,name,pri,desc,status,begin,end,private'; $this->batchSetPost($fields, $oldTodo); - + $this->setPost('idvalue', 0); $this->setPost('date', $this->request('date', date("Y-m-d", strtotime($oldTodo->date)))); $this->setPost('begin', $this->request('begin') ? str_replace(':', '', $this->request('begin')) : $oldTodo->begin); @@ -57,7 +58,7 @@ class todoEntry extends entry $data = $this->getData(); if(!isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $todo = $this->todo->getByID($todoID); $this->send(200, $this->format($todo, 'assignedDate:time,finishedDate:time,closedDate:time')); diff --git a/api/v1/entries/todoactivate.php b/api/v1/entries/todoactivate.php index fe26a2ef2a..77005d42e3 100644 --- a/api/v1/entries/todoactivate.php +++ b/api/v1/entries/todoactivate.php @@ -24,7 +24,8 @@ class todoActivateEntry extends Entry $control->activate($todoID); $data = $this->getData(); - if($data->status == 'fail') return $this->sendError(400, $data->message); + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $todo = $this->loadModel('todo')->getByID($todoID); $this->send(200, $this->format($todo, 'assignedDate:time,finishedDate:time,closedDate:time')); diff --git a/api/v1/entries/todofinish.php b/api/v1/entries/todofinish.php index 6d6f97339d..ebb60dbde8 100644 --- a/api/v1/entries/todofinish.php +++ b/api/v1/entries/todofinish.php @@ -24,7 +24,8 @@ class todoFinishEntry extends Entry $control->finish($todoID); $data = $this->getData(); - if($data->status == 'fail') return $this->sendError(400, $data->message); + if(!$data or !isset($data->status)) return $this->send400('error'); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $todo = $this->loadModel('todo')->getByID($todoID); $this->send(200, $this->format($todo, 'assignedDate:time,finishedDate:time,closedDate:time')); diff --git a/api/v1/entries/todos.php b/api/v1/entries/todos.php index 81e612c152..ac116d4d3e 100644 --- a/api/v1/entries/todos.php +++ b/api/v1/entries/todos.php @@ -24,7 +24,7 @@ class todosEntry extends entry $data = $this->getData(); if(!isset($data->status)) return $this->sendError(400, 'error'); - if(isset($data->status) and $data->status == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); $pager = $data->data->pager; $result = array(); diff --git a/api/v1/entries/users.php b/api/v1/entries/users.php index aa68973ca1..588bef02b2 100644 --- a/api/v1/entries/users.php +++ b/api/v1/entries/users.php @@ -73,7 +73,7 @@ class usersEntry extends entry $control->create(); $data = $this->getData(); - if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message); + if(isset($data->status) and $data->status == 'fail') return $this->sendError(zget($data, 'code', 400), $data->message); if(isset($data->result) and !isset($data->id)) return $this->sendError(400, $data->message); $user = $this->loadModel('user')->getByID($data->id, 'id'); diff --git a/config/routes.php b/config/routes.php index 3384a81bf9..36e75c4167 100644 --- a/config/routes.php +++ b/config/routes.php @@ -50,16 +50,16 @@ $routes['/products/:id/projects'] = 'productProjects'; $routes['/projects'] = 'projects'; $routes['/projects/:id'] = 'project'; -$routes['/projects/:project/executions'] = 'executions'; -$routes['/executions'] = 'executions'; -$routes['/executions/:id'] = 'execution'; +$routes['/projects/:id/executions'] = 'executions'; +$routes['/executions'] = 'executions'; +$routes['/executions/:id'] = 'execution'; -$routes['/executions/:execution/tasks'] = 'tasks'; -$routes['/tasks'] = 'tasks'; -$routes['/tasks/:id'] = 'task'; -$routes['/tasks/:id/assignto'] = 'taskAssignTo'; -$routes['/tasks/:id/start'] = 'taskStart'; -$routes['/tasks/:id/finish'] = 'taskFinish'; +$routes['/executions/:id/tasks'] = 'tasks'; +$routes['/tasks'] = 'tasks'; +$routes['/tasks/:id'] = 'task'; +$routes['/tasks/:id/assignto'] = 'taskAssignTo'; +$routes['/tasks/:id/start'] = 'taskStart'; +$routes['/tasks/:id/finish'] = 'taskFinish'; $routes['/users'] = 'users'; $routes['/users/:id'] = 'user'; @@ -73,16 +73,17 @@ $routes['/programs/:id/stakeholders'] = 'stakeholders'; $routes['/products/:id/issues'] = 'productIssues'; $routes['/projects/:id/issues'] = 'issues'; $routes['/issues'] = 'issues'; -$routes['/issues/:issueID'] = 'issue'; +$routes['/issues/:id'] = 'issue'; $routes['/todos'] = 'todos'; $routes['/todos/:id'] = 'todo'; $routes['/todos/:id/finish'] = 'todoFinish'; $routes['/todos/:id/activate'] = 'todoActivate'; -$routes['/projects/:projectID/builds'] = 'builds'; -$routes['/builds'] = 'builds'; -$routes['/builds/:id'] = 'build'; +$routes['/projects/:id/builds'] = 'builds'; +$routes['/executions/:id/builds'] = 'executionBuilds'; +$routes['/builds'] = 'builds'; +$routes['/builds/:id'] = 'build'; $routes['/products/:id/testcases'] = 'testcases'; $routes['/projects/:id/testcases'] = 'projectCases'; diff --git a/framework/api/entry.class.php b/framework/api/entry.class.php index a68bd080e0..f88046f590 100644 --- a/framework/api/entry.class.php +++ b/framework/api/entry.class.php @@ -589,6 +589,8 @@ class baseEntry return $value; case 'bool': return !empty($value); + case 'int': + return (int) $value; case 'idList': $values = explode(',', $value); if(empty($values)) return array(); @@ -599,6 +601,16 @@ class baseEntry if($val !== '') $idList[] = (int) $val; } return $idList; + case 'stringList': + $values = explode(',', $value); + if(empty($values)) return array(); + + $stringList = array(); + foreach($values as $val) + { + if($val !== '') $stringList[] = $val; + } + return $stringList; default: return $value; } diff --git a/framework/api/router.class.php b/framework/api/router.class.php index c643a2f50d..baf63f2ea1 100644 --- a/framework/api/router.class.php +++ b/framework/api/router.class.php @@ -82,13 +82,13 @@ class api extends router $this->httpMethod = strtolower($_SERVER['REQUEST_METHOD']); - $fileName = substr($_SERVER['SCRIPT_FILENAME'], strlen($_SERVER['DOCUMENT_ROOT'])); - $this->path = substr($_SERVER['REQUEST_URI'], strlen($fileName) + 1); + $fileName = ltrim(substr($_SERVER['SCRIPT_FILENAME'], strlen($_SERVER['DOCUMENT_ROOT'])), '/'); + $this->path = substr(ltrim($_SERVER['REQUEST_URI'], '/'), strlen($fileName) + 1); if(strpos($this->path, '?') > 0) $this->path = strstr($this->path, '?', true); - $subPos = $this->path ? strpos($this->path, '/') : 0; - $this->version = $subPos ? substr($this->path, 0, $subPos) : ''; - $this->path = $subPos ? substr($this->path, $subPos) : ''; + $subPos = $this->path ? strpos($this->path, '/') : false; + $this->version = $subPos !== false ? substr($this->path, 0, $subPos) : ''; + $this->path = $subPos !== false ? substr($this->path, $subPos) : ''; $this->loadApiLang(); } diff --git a/module/bug/model.php b/module/bug/model.php index 5ab908f07d..8443e66685 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -1205,7 +1205,7 @@ class bugModel extends model $this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->where('id')->eq((int)$bugID)->exec(); $this->dao->update(TABLE_BUG)->set('activatedCount = activatedCount + 1')->where('id')->eq((int)$bugID)->exec(); - $openedBuilds = $this->post->openedBuild; + $openedBuilds = explode(',', $oldBug->openedBuild); if($openedBuilds) { $this->loadModel('build'); @@ -2499,7 +2499,7 @@ class bugModel extends model } $allBranch = "`branch` = 'all'"; - if($branch !== 'all' and strpos($bugQuery, '`branch` =') === false) $bugQuery .= " AND `branch` in('$branch')"; + if($branch !== 'all' and strpos($bugQuery, '`branch` =') === false) $bugQuery .= " AND `branch` in('0','$branch')"; if(strpos($bugQuery, $allBranch) !== false) $bugQuery = str_replace($allBranch, '1', $bugQuery); $allProject = "`project` = 'all'"; diff --git a/module/build/control.php b/module/build/control.php index 77fa967f8f..b21ca4419d 100644 --- a/module/build/control.php +++ b/module/build/control.php @@ -492,8 +492,8 @@ class build extends control $this->config->product->search['actionURL'] = $this->createLink('build', 'view', "buildID=$buildID&type=story&link=true¶m=" . helper::safe64Encode("&browseType=bySearch&queryID=myQueryID")); $this->config->product->search['queryID'] = $queryID; $this->config->product->search['style'] = 'simple'; - $this->config->product->search['params']['plan']['values'] = $this->loadModel('productplan')->getForProducts(array($build->product => $build->product)); - $this->config->product->search['params']['module']['values'] = $this->tree->getOptionMenu($build->product, 'story', 0); + $this->config->product->search['params']['plan']['values'] = $this->loadModel('productplan')->getPairsForStory($build->product, $build->branch, 'skipParent'); + $this->config->product->search['params']['module']['values'] = $this->tree->getOptionMenu($build->product, 'story', 0, $build->branch); $this->config->product->search['params']['status'] = array('operator' => '=', 'control' => 'select', 'values' => $this->lang->story->statusList); if($product->type == 'normal') @@ -503,9 +503,11 @@ class build extends control } else { - $this->config->product->search['fields']['branch'] = sprintf($this->lang->product->branch, $this->lang->product->branchName[$product->type]); - $branches = array('' => '') + $this->loadModel('branch')->getPairs($build->product, 'noempty'); - if($build->branch) $branches = array('' => '', $build->branch => $branches[$build->branch]); + $branchPairs = $this->loadModel('branch')->getPairs($build->product, 'noempty'); + $branches = array('' => '') + array(BRANCH_MAIN => $this->lang->branch->main); + if($build->branch) $branches += array($build->branch => $branchPairs[$build->branch]); + + $this->config->product->search['fields']['branch'] = sprintf($this->lang->product->branch, $this->lang->product->branchName[$product->type]); $this->config->product->search['params']['branch']['values'] = $branches; } $this->loadModel('search')->setSearchParams($this->config->product->search); @@ -516,7 +518,7 @@ class build extends control } else { - $allStories = $this->story->getExecutionStories($build->execution, 0, 0, 't1.`order`_desc', 'byProduct', $build->product, 'story', $build->stories, $pager); + $allStories = $this->story->getExecutionStories($build->execution, $build->product, 0, 't1.`order`_desc', 'byBranch', $build->branch, 'story', $build->stories, $pager); } $this->view->allStories = $allStories; @@ -609,8 +611,8 @@ class build extends control $this->config->bug->search['actionURL'] = $this->createLink('build', 'view', "buildID=$buildID&type=bug&link=true¶m=" . helper::safe64Encode("&browseType=bySearch&queryID=myQueryID")); $this->config->bug->search['queryID'] = $queryID; $this->config->bug->search['style'] = 'simple'; - $this->config->bug->search['params']['plan']['values'] = $this->loadModel('productplan')->getForProducts(array($build->product => $build->product)); - $this->config->bug->search['params']['module']['values'] = $this->loadModel('tree')->getOptionMenu($build->product, $viewType = 'bug', $startModuleID = 0); + $this->config->bug->search['params']['plan']['values'] = $this->loadModel('productplan')->getPairsForStory($build->product, $build->branch, 'skipParent'); + $this->config->bug->search['params']['module']['values'] = $this->loadModel('tree')->getOptionMenu($build->product, 'bug', 0, $build->branch); $this->config->bug->search['params']['execution']['values'] = $this->loadModel('product')->getExecutionPairsByProduct($build->product, 0, 'id_desc', $this->session->project); $this->config->bug->search['params']['openedBuild']['values'] = $this->build->getProductBuildPairs($build->product, $branch = 0, $params = ''); $this->config->bug->search['params']['resolvedBuild']['values'] = $this->config->bug->search['params']['openedBuild']['values']; @@ -624,9 +626,11 @@ class build extends control } else { - $this->config->bug->search['fields']['branch'] = sprintf($this->lang->product->branch, $this->lang->product->branchName[$product->type]); - $branches = array('' => '') + $this->loadModel('branch')->getPairs($build->product, 'noempty'); - if($build->branch) $branches = array('' => '', $build->branch => $branches[$build->branch]); + $branchPairs = $this->loadModel('branch')->getPairs($build->product, 'noempty'); + $branches = array('' => '') + array(BRANCH_MAIN => $this->lang->branch->main); + if($build->branch) $branches += array($build->branch => $branchPairs[$build->branch]); + + $this->config->bug->search['fields']['branch'] = sprintf($this->lang->product->branch, $this->lang->product->branchName[$product->type]); $this->config->bug->search['params']['branch']['values'] = $branches; } $this->loadModel('search')->setSearchParams($this->config->bug->search); diff --git a/module/build/js/common.js b/module/build/js/common.js index e92d9470ad..599c9cba24 100644 --- a/module/build/js/common.js +++ b/module/build/js/common.js @@ -15,7 +15,7 @@ function loadBranches(productID) oldBranch = productGroups[productID]['branches']; } - executionID = $('#execution').val(); + executionID = currentTab == 'execution' ? executionID : $('#execution').val(); $.get(createLink('branch', 'ajaxGetBranches', 'productID=' + productID + '&oldBranch=0¶m=active&projectID=' + executionID), function(data) { if(data) diff --git a/module/build/model.php b/module/build/model.php index 260bbbf0c0..b5176147c5 100644 --- a/module/build/model.php +++ b/module/build/model.php @@ -160,10 +160,11 @@ class buildModel extends model * @param int $executionID * @param string $type all|product|bysearch * @param int|string $param productID|buildQuery + * @param string $orderBy * @access public * @return array */ - public function getExecutionBuilds($executionID, $type = '', $param = '') + public function getExecutionBuilds($executionID, $type = '', $param = '', $orderBy = 't1.date_desc,t1.id_desc') { return $this->dao->select('t1.*, t2.name as executionName, t3.name as productName, t4.name as branchName') ->from(TABLE_BUILD)->alias('t1') @@ -174,7 +175,7 @@ class buildModel extends model ->andWhere('t1.deleted')->eq(0) ->beginIF($type == 'product' and $param)->andWhere('t1.product')->eq($param)->fi() ->beginIF($type == 'bysearch')->andWhere($param)->fi() - ->orderBy('t1.date DESC, t1.id desc') + ->orderBy($orderBy) ->fetchAll('id'); } diff --git a/module/build/view/create.html.php b/module/build/view/create.html.php index 1ede2bdad7..996195e756 100644 --- a/module/build/view/create.html.php +++ b/module/build/view/create.html.php @@ -92,5 +92,7 @@ - + + +app->tab);?> diff --git a/module/common/model.php b/module/common/model.php index 06ad9ee399..a752ccf8c8 100644 --- a/module/common/model.php +++ b/module/common/model.php @@ -1865,9 +1865,10 @@ EOD; { $queryObjects = $this->dao->query($sql); $objectList = array(); + $key = 'id'; while($object = $queryObjects->fetch()) { - $key = (!$this->session->$typeOnlyCondition and $type == 'testcase' and isset($object->case)) ? 'case' : 'id'; + if(!$this->session->$typeOnlyCondition and $type == 'testcase' and isset($object->case)) $key = 'case'; $id = $object->$key; $objectList[$id] = $id; } diff --git a/module/doc/control.php b/module/doc/control.php index 71f285352a..793b4eb0fc 100644 --- a/module/doc/control.php +++ b/module/doc/control.php @@ -476,7 +476,11 @@ class doc extends control /* Get doc. */ $docID = (int)$docID; $doc = $this->doc->getById($docID, $version, true); - if(!$doc) die(js::error($this->lang->notFound) . js::locate($this->createLink('doc', 'index'))); + if(!$doc) + { + if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'fail', 'code' => 404, 'message' => '404 Not found')); + die(js::error($this->lang->notFound) . js::locate($this->createLink('doc', 'index'))); + } /* The global search opens in the document library. */ if(!isonlybody()) @@ -496,7 +500,7 @@ class doc extends control } $browseLink = inLink('objectLibs', "type=$type&objectID=$objectID&libID=$libID&docID=$docID"); - $this->locate($browseLink); + if(!(defined('RUN_MODE') && RUN_MODE == 'api')) $this->locate($browseLink); } if($doc->contentType == 'markdown') diff --git a/module/execution/control.php b/module/execution/control.php index 1dce3dc299..b46be38eb5 100644 --- a/module/execution/control.php +++ b/module/execution/control.php @@ -986,10 +986,11 @@ class execution extends control * @param int $executionID * @param string $type all|product|bysearch * @param int $param + * @param string $orderBy * @access public * @return void */ - public function build($executionID = 0, $type = 'all', $param = 0) + public function build($executionID = 0, $type = 'all', $param = 0, $orderBy = 't1.date_desc,t1.id_desc') { /* Load module and set session. */ $this->loadModel('testtask'); @@ -1015,7 +1016,7 @@ class execution extends control } else { - $builds = $this->loadModel('build')->getExecutionBuilds((int)$executionID, $type, $param); + $builds = $this->loadModel('build')->getExecutionBuilds((int)$executionID, $type, $param, $orderBy); } /* Set execution builds. */ @@ -2507,7 +2508,7 @@ class execution extends control if($browseType == 'bySearch') { - $allStories = $this->story->getBySearch('', 0, $queryID, 'id', $objectID); + $allStories = $this->story->getBySearch('', '', $queryID, 'id', $objectID); } else { diff --git a/module/file/control.php b/module/file/control.php index b25ccae783..cb23328f8b 100644 --- a/module/file/control.php +++ b/module/file/control.php @@ -115,7 +115,11 @@ class file extends control { if(session_id() != $this->app->sessionID) helper::restartSession($this->app->sessionID); $file = $this->file->getById($fileID); - if(empty($file)) die("{$this->lang->file->fileNotFound}"); + if(empty($file)) + { + if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'fail', 'code' => 404, 'message' => $this->lang->file->fileNotFound)); + die("{$this->lang->file->fileNotFound}"); + } /* Judge the mode, down or open. */ $mode = 'down'; @@ -156,6 +160,7 @@ class file extends control } else { + if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'fail', 'code' => 404, 'message' => $this->lang->file->fileNotFound)); die("{$this->lang->file->fileNotFound}"); } } diff --git a/module/program/control.php b/module/program/control.php index 2c659df5ce..1cf3695725 100644 --- a/module/program/control.php +++ b/module/program/control.php @@ -156,10 +156,9 @@ class program extends control { $programID = $this->program->create(); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); - if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $programID)); $this->loadModel('action')->create('program', $programID, 'opened'); - return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $programID, 'locate' => inlink('browse'))); } $extra = str_replace(array(',', ' '), array('&', ''), $extra); @@ -386,7 +385,11 @@ class program extends control public function delete($programID, $confirm = 'no') { $childrenCount = $this->dao->select('count(*) as count')->from(TABLE_PROGRAM)->where('parent')->eq($programID)->andWhere('deleted')->eq(0)->fetch('count'); - if($childrenCount) die(js::alert($this->lang->program->hasChildren)); + if($childrenCount) + { + if($this->viewType == 'json' or (defined('RUN_MODE') && RUN_MODE == 'api')) return $this->send(array('result' => 'fail', 'message' => 'Cannot delete the program has children')); + die(js::alert($this->lang->program->hasChildren)); + } $productCount = $this->dao->select('count(*) as count')->from(TABLE_PRODUCT)->where('program')->eq($programID)->andWhere('deleted')->eq(0)->fetch('count'); if($productCount) die(js::alert($this->lang->program->hasProduct)); diff --git a/module/project/css/browse.css b/module/project/css/browse.css index c89de26fc7..a9b6f2eebe 100644 --- a/module/project/css/browse.css +++ b/module/project/css/browse.css @@ -11,3 +11,7 @@ td.c-PM {white-space: nowrap; overflow: hidden;} .icon-cards-view {padding-left: 7px; font-size: 16px;} .icon-list {padding-left: 7px;} .panel-actions {position: relative; padding: 0 0;} +@media screen and (max-width: 1460px) +{ + th.c-name {width: 360px !important;} +} diff --git a/module/story/model.php b/module/story/model.php index f6a4e299cf..5e6cc1ab8d 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -47,7 +47,7 @@ class storyModel extends model ->andWhere('t2.type')->in('sprint,stage') ->orderBy('t1.`order` DESC') ->fetchAll('project'); - $story->tasks = $this->dao->select('id, name, assignedTo, execution, status, consumed, `left`')->from(TABLE_TASK)->where('story')->eq($storyID)->andWhere('deleted')->eq(0)->orderBy('id DESC')->fetchGroup('execution'); + $story->tasks = $this->dao->select('id, name, assignedTo, execution, status, consumed, `left`,type')->from(TABLE_TASK)->where('story')->eq($storyID)->andWhere('deleted')->eq(0)->orderBy('id DESC')->fetchGroup('execution'); $story->stages = $this->dao->select('*')->from(TABLE_STORYSTAGE)->where('story')->eq($storyID)->fetchPairs('branch', 'stage'); //$story->bugCount = $this->dao->select('COUNT(*)')->alias('count')->from(TABLE_BUG)->where('story')->eq($storyID)->fetch('count'); //$story->caseCount = $this->dao->select('COUNT(*)')->alias('count')->from(TABLE_CASE)->where('story')->eq($storyID)->fetch('count'); @@ -2446,10 +2446,18 @@ class storyModel extends model $branches = array(); foreach($products as $product) { - foreach($product->branches as $branchID) $branches[$branchID] = $branchID; + if($product->type != 'normal') + { + $branches[BRANCH_MAIN] = BRANCH_MAIN; + foreach($product->branches as $branchID) + { + if($branch == BRANCH_MAIN and $branchID) continue; + $branches[$branchID] = $branchID; + } + } } $branches = join(',', $branches); - if($branches) $storyQuery .= " AND `branch`" . helper::dbIN($branches); + $storyQuery .= " AND `branch`" . helper::dbIN($branches); if($this->app->moduleName == 'release' or $this->app->moduleName == 'build') { @@ -2590,7 +2598,7 @@ class storyModel extends model else { $productParam = ($type == 'byproduct' and $param) ? $param : $this->cookie->storyProductParam; - $branchParam = $branchID = ($type == 'bybranch' and $param !== '') ? $param : $this->cookie->storyBranchParam; + $branchParam = ($type == 'bybranch' and $param !== '') ? $param : $this->cookie->storyBranchParam; $moduleParam = ($type == 'bymodule' and $param) ? $param : $this->cookie->storyModuleParam; $modules = (empty($moduleParam) or strpos(',all,unclosed,bymodule,', ",$type,") === false) ? array() : $this->dao->select('id')->from(TABLE_MODULE)->where('path')->like("%,$moduleParam,%")->andWhere('type')->eq('story')->andWhere('deleted')->eq(0)->fetchPairs(); if(strpos($branchParam, ',') !== false) list($productParam, $branchParam) = explode(',', $branchParam); @@ -2617,7 +2625,7 @@ class storyModel extends model ->beginIF($excludeStories)->andWhere('t2.id')->notIN($excludeStories)->fi() ->beginIF($execution->type == 'project') ->beginIF(!empty($productID))->andWhere('t1.product')->eq($productID) - ->beginIF($type == 'bybranch' and $branchParam !== '')->andWhere('t2.branch')->eq($branchParam)->fi() + ->beginIF($type == 'bybranch' and $branchParam !== '')->andWhere('t2.branch')->in("0,$branchParam")->fi() ->beginIF(strpos('changed|closed', $type) !== false)->andWhere('t2.status')->eq($type)->fi() ->beginIF($type == 'unclosed')->andWhere('t2.status')->in(array_keys($unclosedStatus))->fi() ->beginIF($type == 'linkedexecution')->andWhere('t2.id')->in($storyIdList)->fi() @@ -2628,7 +2636,6 @@ class storyModel extends model ->beginIF($this->session->executionStoryBrowseType and strpos('changed|', $this->session->executionStoryBrowseType) !== false)->andWhere('t2.status')->in(array_keys($unclosedStatus))->fi() ->fi() ->beginIF($this->session->storyBrowseType and strpos('changed|', $this->session->storyBrowseType) !== false)->andWhere('t2.status')->in(array_keys($unclosedStatus))->fi() - ->beginIF(!empty($branchParam))->andWhere('t2.branch')->eq($branchParam)->fi() ->beginIF($modules)->andWhere('t2.module')->in($modules)->fi() ->andWhere('t2.deleted')->eq(0) ->orderBy($orderBy) diff --git a/module/testcase/control.php b/module/testcase/control.php index d9385ff39c..0f6a14dba3 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -172,7 +172,7 @@ class testcase extends control $actionURL = $this->createLink($currentModule, $currentMethod, $projectParam . "productID=$productID&branch=$branch&browseType=bySearch&queryID=myQueryID"); $this->config->testcase->search['onMenuBar'] = 'yes'; - $this->testcase->buildSearchForm($productID, $this->products, $queryID, $actionURL); + $this->testcase->buildSearchForm($productID, $this->products, $queryID, $actionURL, $projectID); $showModule = !empty($this->config->datatable->testcaseBrowse->showModule) ? $this->config->datatable->testcaseBrowse->showModule : ''; @@ -1713,7 +1713,7 @@ class testcase extends control * @access public * @return void */ - public function importFromLib($productID, $branch = 0, $libID = 0, $orderBy = 'id_desc', $browseType = '', $queryID = 0, $recTotal = 0, $recPerPage = 20, $pageID = 1) + public function importFromLib($productID, $branch = 0, $libID = 0, $orderBy = 'id_desc', $browseType = '', $queryID = 0, $recTotal = 0, $recPerPage = 20, $pageID = 1, $projectID = 0) { $browseType = strtolower($browseType); $queryID = (int)$queryID; @@ -1764,7 +1764,7 @@ class testcase extends control $this->view->libModules = $this->tree->getOptionMenu($libID, 'caselib'); $this->view->pager = $pager; $this->view->orderBy = $orderBy; - $this->view->branches = $this->loadModel('branch')->getPairs($productID); + $this->view->branches = array('0' => $this->lang->branch->main) + $this->loadModel('branch')->getPairs($productID, '', $projectID); $this->view->browseType = $browseType; $this->view->queryID = $queryID; diff --git a/module/testcase/model.php b/module/testcase/model.php index 132f5b5d51..18d3532409 100644 --- a/module/testcase/model.php +++ b/module/testcase/model.php @@ -465,7 +465,7 @@ class testcaseModel extends model /* Cases need confirmed. */ elseif($browseType == 'needconfirm') { - $cases = $this->dao->select('t1.*, t2.title AS storyTitle')->from(TABLE_CASE)->alias('t1') + $cases = $this->dao->select('distinct t1.*, t2.title AS storyTitle')->from(TABLE_CASE)->alias('t1') ->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story = t2.id') ->leftJoin(TABLE_PROJECTCASE)->alias('t3')->on('t1.id = t3.case') ->where("t2.status = 'active'") @@ -1446,10 +1446,11 @@ class testcaseModel extends model * @param array $products * @param int $queryID * @param string $actionURL + * @param string $projectID * @access public * @return void */ - public function buildSearchForm($productID, $products, $queryID, $actionURL) + public function buildSearchForm($productID, $products, $queryID, $actionURL, $projectID) { $product = ($this->app->tab == 'project' and empty($productID)) ? $products : array($productID => $products[$productID]) + array('all' => $this->lang->testcase->allProduct); $this->config->testcase->search['params']['product']['values'] = $product; @@ -1473,7 +1474,7 @@ class testcaseModel extends model { $productInfo = $this->loadModel('product')->getByID($productID); $this->config->testcase->search['fields']['branch'] = sprintf($this->lang->product->branch, $this->lang->product->branchName[$productInfo->type]); - $this->config->testcase->search['params']['branch']['values'] = array('' => '', '0' => $this->lang->branch->main) + $this->loadModel('branch')->getPairs($productID, 'noempty') + array('all' => $this->lang->branch->all); + $this->config->testcase->search['params']['branch']['values'] = array('' => '', '0' => $this->lang->branch->main) + $this->loadModel('branch')->getPairs($productID, '', $projectID) + array('all' => $this->lang->branch->all); } if(!$this->config->testcase->needReview) unset($this->config->testcase->search['params']['status']['values']['wait']); $this->config->testcase->search['actionURL'] = $actionURL; diff --git a/module/testcase/view/caseheader.html.php b/module/testcase/view/caseheader.html.php index 9853fe669d..a35a43d4e7 100644 --- a/module/testcase/view/caseheader.html.php +++ b/module/testcase/view/caseheader.html.php @@ -143,7 +143,7 @@ $class = common::hasPriv('testcase', 'importFromLib') ? '' : "class=disabled"; $misc = common::hasPriv('testcase', 'importFromLib') ? "data-app='{$this->app->tab}'" : "class=disabled"; - $link = common::hasPriv('testcase', 'importFromLib') ? $this->createLink('testcase', 'importFromLib', "productID=$productID&branch=$branch") : '#'; + $link = common::hasPriv('testcase', 'importFromLib') ? $this->createLink('testcase', 'importFromLib', "productID=$productID&branch=$branch&libID=0&orderBy=id_desc&browseType=&queryID=10&recTotal=0&recPerPage=20&pageID=1&projectID=$projectID") : '#'; echo "
  • " . html::a($link, $lang->testcase->importFromLib, '', $misc . "data-app={$this->app->tab}") . "
  • "; ?> diff --git a/module/testtask/lang/zh-cn.php b/module/testtask/lang/zh-cn.php index 566d2b28f3..1f7d376eda 100644 --- a/module/testtask/lang/zh-cn.php +++ b/module/testtask/lang/zh-cn.php @@ -118,10 +118,9 @@ $lang->testtask->statusList['doing'] = '进行中'; $lang->testtask->statusList['done'] = '已关闭'; $lang->testtask->statusList['blocked'] = '被阻塞'; -$lang->testtask->priList[0] = ''; -$lang->testtask->priList[3] = '3'; $lang->testtask->priList[1] = '1'; $lang->testtask->priList[2] = '2'; +$lang->testtask->priList[3] = '3'; $lang->testtask->priList[4] = '4'; $lang->testtask->unlinkedCases = '未关联'; diff --git a/module/testtask/view/create.html.php b/module/testtask/view/create.html.php index de900349e5..9e4f2db1b8 100644 --- a/module/testtask/view/create.html.php +++ b/module/testtask/view/create.html.php @@ -60,7 +60,7 @@
    testtask->pri;?> - testtask->priList, 0, "class='form-control chosen'");?> + testtask->priList, 3, "class='form-control chosen'");?>
    diff --git a/module/tree/model.php b/module/tree/model.php index 02c03c939f..45a42c3468 100644 --- a/module/tree/model.php +++ b/module/tree/model.php @@ -136,17 +136,14 @@ class treeModel extends model if($type == 'line') $rootID = 0; - $branches = array($branch => ''); + $branches = array(); if(strpos('story|bug|case', $type) !== false) { $product = $this->loadModel('product')->getById($rootID); if($product and $product->type != 'normal') { - $branchList = array('null' => '') + $this->loadModel('branch')->getPairs($rootID, 'all'); - - if(!$branch) $newBranches['null'] = ''; - $newBranches[$branch] = $branchList[$branch]; - $branches = $branch === 'all' ? $branchList : $newBranches; + $branchPairs = $this->loadModel('branch')->getPairs($rootID, 'all'); + $branches = $branch === 'all' ? $branchPairs : array($branch => $branchPairs[$branch]); } elseif($product and $product->type == 'normal') { @@ -157,11 +154,15 @@ class treeModel extends model $treeMenu = array(); foreach($branches as $branchID => $branch) { - $stmt = $this->dbh->query($this->buildMenuQuery($rootID, $type, $startModule, $branchID)); - $modules = array(); + $stmt = $this->dbh->query($this->buildMenuQuery($rootID, $type, $startModule, $branchID)); + $modules = array(); while($module = $stmt->fetch()) $modules[$module->id] = $module; - foreach($modules as $module) $this->buildTreeArray($treeMenu, $modules, $module, (empty($branch) or $branch == 'null') ? '/' : "/$branch/"); + foreach($modules as $module) + { + $branchName = ($product->type != 'normal' and $module->branch == BRANCH_MAIN) ? $this->lang->branch->main : $branch; + $this->buildTreeArray($treeMenu, $modules, $module, (empty($branchName)) ? '/' : "/$branchName/"); + } } ksort($treeMenu); diff --git a/module/user/model.php b/module/user/model.php index c79cc18c01..fb6968e130 100644 --- a/module/user/model.php +++ b/module/user/model.php @@ -60,8 +60,6 @@ class userModel extends model return $this->dao->select('id,account,realname,avatar,role')->from(TABLE_USER) ->where('account')->in($accounts) - ->andWhere('deleted')->eq(0) - ->andWhere('type')->eq('inside') ->fetchAll($keyField); }