Skip to content

Commit de2b5c6

Browse files
committed
完善一些字段的显示
1 parent 81dfc64 commit de2b5c6

10 files changed

+106
-20
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Redmine: <http://www.redmine.org/projects/redmine/wiki/Rest_api>
1414

1515
Redmine中只有Issue的概念,而禅道中有需求(Story)、任务(Task)、Bug三种形式的概念,相应数据的ID没有统一管理,所以概念上无法完全统一,只能一一独立实现,然后从接口上分离,在IDE中分开配置。
1616

17+
后面设定一种关联逻辑,由于跟研发直接相关的为任务与 bug 两种,所以将Redmine 中 Category 这个概念用于区分这两种数据.在任务 id 与 bug id 加上固定的前缀来区分,这样可以合并数据显示.
18+
1719
## 配置
1820

1921
为了实现兼容特性,对禅道数据表做了少量的变更,主要是增加字段。

inc/zentao/nb/enum/IssueCategory.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace zentao\nb\enum;
4+
5+
/**
6+
* Issue分类 枚举类型定义
7+
* 尝试将禅道中的任务和 bug 以 redmine 分类的形式提供
8+
*/
9+
class IssueCategory {
10+
11+
const BUG = 1;
12+
const TASK = 2;
13+
14+
/**
15+
* bug 编号的固定前缀
16+
*/
17+
const PREFIX_BUG = 100;
18+
19+
/**
20+
* 任务编号的固定前缀
21+
*/
22+
const PREFIX_TASK = 200;
23+
24+
public function getLabels() {
25+
return array(
26+
self::BUG => 'Bug',
27+
self::TASK => 'Task'
28+
);
29+
}
30+
}

inc/zentao/nb/enum/IssueTracker.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace zentao\nb\enum;
4+
5+
class IssueTracker {
6+
7+
/**
8+
*
9+
* @var array issue类型标识与 整型 id 的对应 只支持系统默认的类型
10+
*/
11+
protected $map = array(
12+
'null' => 0,
13+
'bydesign' => 1,
14+
'duplicate' => 2,
15+
'external' => 3,
16+
'fixed' => 4,
17+
'notrepro' => 5,
18+
'postponed' => 6,
19+
'willnotfix' => 7,
20+
'tostory' => 8
21+
);
22+
23+
public function getLabel() {
24+
25+
}
26+
}

inc/zentao/nb/resource/Issue.php

+13-11
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ public function fetchAll($format = 'json') {
1717

1818
$model = $this->loadModel('bug');
1919

20-
$issues = $model->getByList();
20+
$project_id = !empty($_GET['project_id']) ? (int) $_GET['project_id'] : null;
21+
if ($project_id > 0) {
22+
$issues = $model->getProjectBugs($project_id);
23+
} else {
24+
$issues = $model->getByList();
25+
}
2126
$total_count = $model->dao->count();
22-
//var_dump($issues);
2327

2428
$limit = !empty($_GET['limit']) ? (int)$_GET['limit'] : 0;
2529
$offset = !empty($_GET['offset']) ? (int)$_GET['offset'] : 0;
@@ -37,11 +41,11 @@ public function fetchAll($format = 'json') {
3741
'id' => (int)$issue->id,
3842
'subject' => $issue->title,
3943
'project' => array('id' => $issue->project, 'name' => $issue->project .'111'),
40-
'tracker' => array('id' => 1, 'name' => '11'),
44+
'tracker' => array('id' => 1, 'name' => $issue->type),
4145
'status' => array('id' => 1, 'name' => 'issue'),
42-
'priority' => array('id' => 1, 'name' => '11'),
43-
'author' => array('id' => 1, 'name' => 'admin'), //TODO
44-
'assigned_to' => array('id' => 1, 'name' => 'admin'), //TODO
46+
'priority' => array('id' => $issue->pri, 'name' => '11'),
47+
'author' => array('id' => 1, 'name' => $issue->openedBy), //TODO
48+
'assigned_to' => array('id' => 1, 'name' => $issue->assignedTo), //TODO
4549
'description' => '',//$issue->steps
4650
'start_date' => date('Y-m-d', strtotime($issue->assignedDate)),
4751
'due_date' => date('Y-m-d', strtotime($issue->assignedDate) + 1000000),
@@ -62,8 +66,6 @@ public function fetchAll($format = 'json') {
6266
* @param string $format
6367
*/
6468
public function fetch($id, $format = 'json') {
65-
//echo '{"issue":{"id":1,"project":{"id":1,"name":"project1"},"tracker":{"id":1,"name":"track tag1"},"status":{"id":1,"name":"issue"},"priority":{"id":1,"name":"1"},"author":{"id":2,"name":"Redmine Admin"},"assigned_to":{"id":2,"name":"Redmine Admin"},"subject":"issue 144445555","description":"","start_date":"2015-11-15","due_date":"2015-11-17","done_ratio":0,"spent_hours":0.0,"created_on":"2015-11-15T06:36:35Z","updated_on":"2015-11-15T06:38:28Z","attachments":[],"journals":[{"id":1,"user":{"id":2,"name":"Redmine Admin"},"notes":"","created_on":"2015-11-15T06:38:02Z","details":[{"property":"attr","name":"subject","old_value":"issue 1","new_value":"issue 144445555"}]},{"id":2,"user":{"id":2,"name":"Redmine Admin"},"notes":"","created_on":"2015-11-15T06:38:28Z","details":[{"property":"attr","name":"due_date","new_value":"2015-11-17"},{"property":"attr","name":"assigned_to_id","new_value":"2"}]}],"watchers":[]}}';
66-
//exit;
6769
$model = $this->loadModel('bug');
6870
$issue = $model->getById($id);
6971
if (!$issue) {
@@ -76,9 +78,9 @@ public function fetch($id, $format = 'json') {
7678
'subject' => $issue->title,
7779
'tracker' => array('id' => 1, 'name' => '11'),//
7880
'priority' => array('id' => 1, 'name' => '11'),
79-
'author' => array('id' => 1, 'name' => 'admin'),
80-
'assigned_to' => array('id' => 1, 'name' => 'admin'),
81-
'description' => 'yyy', //$issue->steps
81+
'author' => array('id' => 1, 'name' => $issue->openedBy),
82+
'assigned_to' => array('id' => 1, 'name' => $issue->assignedTo),
83+
'description' => '', //$issue->steps
8284
'start_date' => date('Y-m-d', strtotime($issue->assignedDate)),
8385
'due_date' => date('Y-m-d', strtotime($issue->assignedDate) + 1000000),
8486
'done_ratio' => 0,

inc/zentao/nb/resource/IssueCategory.php

+20-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace zentao\nb\resource;
44

5+
use zentao\nb\enum\IssueCategory AS Category;
6+
57
/**
68
* 项目自行定义的问题分类
79
*/
@@ -14,7 +16,7 @@ public function fetchAll($format = 'json') {
1416
$issue_statuses = array();
1517
foreach ($statuses as $key => $status) {
1618
if ($status == '') {
17-
$status = 'unknown';
19+
$status = '-';
1820
}
1921

2022
$issue_statuses[] = array('id' => $key, 'name' => $status);
@@ -23,7 +25,23 @@ public function fetchAll($format = 'json') {
2325
echo json_encode(array('issue_categories' => $issue_statuses));
2426
}
2527

28+
/**
29+
* 用 分类来区分 禅道中的任务和 bug
30+
* @param int $projectId
31+
* @param string $format
32+
*/
2633
public function fetchAllByProjectId($projectId, $format = 'json') {
27-
echo '{"issue_categories":[{"id":1,"project":{"id":1,"name":"project1"},"name":"qqq"}],"total_count":1}';
34+
$model = $this->loadModel('project');
35+
$project = $model->getById($projectId);//TODO 支持按项目代号查找
36+
if (!$project) {
37+
$this->responseNotExixted();
38+
}
39+
echo json_encode(array(
40+
'issue_categories' => array(
41+
array('id' => Category::BUG, 'name' => 'Bug', 'project' => array('id' => $projectId, 'name' => $project->name)),
42+
array('id' => Category::TASK, 'name' => 'Task', 'project' => array('id' => $projectId, 'name' => $project->name)),
43+
),
44+
'total_count' => 2
45+
));
2846
}
2947
}

inc/zentao/nb/resource/IssueStatus.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function index($format = 'json') {
2525
$issue_statuses = array();
2626
foreach ($statuses as $key => $status) {
2727
if ($status == '') {
28-
$status = 'unknown';
28+
$status = '-';
2929
}
3030

3131
$issue_statuses[] = array('id' => (isset($this->map[$key]) ? $this->map[$key] : $this->map['null']), 'name' => $status);

inc/zentao/nb/resource/ProjectMembership.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ public function fetchAll($projectId, $format = 'json') {
1616

1717
$model = $this->loadModel('project');
1818

19-
$project = $model->getById($id);//TODO 支持按项目代号查找
19+
$project = $model->getById($projectId);//TODO 支持按项目代号查找
2020
if (!$project) {
2121
$this->responseNotExixted();
2222
}
2323

24-
$teams = $model->getTeamMembers($projectId);
2524
$total_count = $model->dao->count();
25+
$limit = !empty($_GET['limit']) ? (int)$_GET['limit'] : 0;
26+
$offset = !empty($_GET['offset']) ? (int)$_GET['offset'] : 0;
27+
if ($offset > 0) {
28+
$this->response(array('memberships' => array(), 'total_count' => $total_count, 'offset' => $limit * $offset, 'limit' => $limit));
29+
}
30+
31+
$teams = $model->getTeamMembers($projectId);
2632

2733
$data = array();
2834
if (!$teams) {
@@ -40,6 +46,6 @@ public function fetchAll($projectId, $format = 'json') {
4046
$data[] = $_team;
4147
}
4248

43-
$this->response(array('memberships' => $data, 'total_count' => $total_count, 'offset' => 0, 'limit' => $total_count));
49+
$this->response(array('memberships' => $data, 'total_count' => $total_count, 'offset' => $limit * $offset, 'limit' => $limit));
4450
}
4551
}

inc/zentao/nb/resource/ProjectVersion.php

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public function fetchAll($projectId, $format = 'json') {
1414

1515
$builds = $model->getProjectBuilds($projectId);
1616
$total_count = $model->dao->count();
17-
//var_dump($builds);exit;
1817

1918
$data = array();
2019
if (!$builds) {

inc/zentao/nb/resource/Query.php

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use zentao\nb\Resource;
66

7+
/**
8+
* redmine 中支持保存用户自定义查询条件
9+
*/
710
class Query extends Resource {
811

912
public function index() {

inc/zentao/nb/resource/Tracker.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace zentao\nb\resource;
44

55
/**
6-
* 问题的类型
6+
* 问题的类型 用 bug 的类型来代替
77
*
88
*/
99
class Tracker extends \zentao\nb\resource {
@@ -30,7 +30,7 @@ public function index($format = 'json') {
3030
$trackers = array();
3131
foreach ($types as $key => $type) {
3232
if ($type == '') {
33-
$type = 'unknown';
33+
$type = '-';
3434
}
3535

3636
$trackers[] = array('id' => (isset($this->map[$key]) ? $this->map[$key] : $this->map['null']), 'name' => $type);

0 commit comments

Comments
 (0)