Skip to content

Commit

Permalink
看板增加默认的选项
Browse files Browse the repository at this point in the history
  • Loading branch information
weichaoduo committed Nov 23, 2020
1 parent 3b94338 commit d497a69
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 15 deletions.
34 changes: 34 additions & 0 deletions app/ctrl/Agile.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ public function pageBoard()
$data['perm_kanban'] = PermissionLogic::check($data['project_id'], UserAuth::getId(), PermissionLogic::MANAGE_KANBAN);
}

$projectFlagModel = new ProjectFlagModel();
$boardDefaultId = (int)$projectFlagModel->getValueByFlag($data['project_id'], 'board_default_id');
$data['board_default_id'] = $boardDefaultId;

$this->render('gitlab/agile/board.php', $data);
}

Expand Down Expand Up @@ -390,6 +394,33 @@ public function saveBoardSetting()
$this->ajaxSuccess('操作成功', $_POST);
}

/**
* @throws \Exception
*/
public function setBoardDefault()
{
$projectId = null;
if (isset($_POST['project_id'])) {
$projectId = (int)$_POST['project_id'];
}
if (empty($projectId)) {
$this->ajaxFailed('参数错误', '项目id不能为空');
}

$boardId = null;
if (isset($_POST['id'])) {
$boardId = (int)$_POST['id'];
}
if (empty($boardId)) {
$err['id'] = '看板id不能为空';
$this->ajaxFailed('参数错误', $err, parent::AJAX_FAILED_TYPE_FORM_ERROR);
}
$projectFlagModel = new ProjectFlagModel();
$projectFlagModel->add($projectId,'board_default_id', $boardId);

$this->ajaxSuccess('操作成功', $_POST);
}

/**
* 添加一个迭代
* @throws \Exception
Expand Down Expand Up @@ -964,6 +995,8 @@ public function fetchBoardsByProject()
$agileBoardModel = new AgileBoardModel();
$defaultBoards = $agileBoardModel->getsByDefault();
$projectBoards = $agileBoardModel->getsByProject($projectId);
$projectFlagModel = new ProjectFlagModel();
$boardDefaultId = (int)$projectFlagModel->getValueByFlag($projectId, 'board_default_id');

$boards = $defaultBoards;
foreach ($projectBoards as $projectBoard) {
Expand All @@ -973,6 +1006,7 @@ public function fetchBoardsByProject()
foreach ($boards as &$board) {
$i++;
$board['i'] = $i;
$board['is_default'] = $boardDefaultId==$board['id'] ? '1' :'0';
}
$data['boards'] = $boards;
$this->ajaxSuccess('success', $data);
Expand Down
9 changes: 9 additions & 0 deletions app/model/agile/AgileBoardModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,22 @@ public function getsByProject($projectId)
return $rows;
}

/**
* @return array
*/
public function getsByDefault()
{
$params = ['project_id' => 0];
$rows = $this->getRows("*", $params);
return $rows;
}

/**
* @param $projectId
* @return int
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\DBAL\Exception\InvalidArgumentException
*/
public function deleteByProjectId($projectId)
{
$conditions = [];
Expand Down
9 changes: 8 additions & 1 deletion app/model/project/ProjectFlagModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,21 @@ public static function getInstance($persistent = false)
return self::$instance[$index];
}

/**
* @param $projectId
* @param $flag
* @param $value
* @return array
* @throws \Exception
*/
public function add($projectId, $flag, $value)
{
$info = [];
$info['project_id'] = $projectId;
$info['flag'] = $flag;
$info['value'] = $value;
$info['update_time'] = time();
$ret = $this->insert($info);
$ret = $this->replace($info);
return $ret;
}

Expand Down
32 changes: 20 additions & 12 deletions app/view/twig/agile/board.twig
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<select id="boards_select" name="boards_select"
class="selectpicker">
{% for board in boards %}
<option value="<?= board['id'] ?>"><?= board['name'] ?></option>
<option value="<?= board['id'] ?>" {% if board_default_id==board['id'] %} selected {% endif %}><?= board['name'] ?></option>
{% endfor %}
</select>
</div>
Expand Down Expand Up @@ -356,17 +356,19 @@
<td>{{range_type}}</td>
<!--<td>{{#if_eq is_filter_backlog 1}} 是 {{^}} 否 {{/if_eq}}</td>
<td>{{#if_eq is_filter_closed 1}} 是 {{^}} 否 {{/if_eq}}</td>-->
<td>{{#if_eq is_default 1}} <a class="btn btn-transparent" href="#">默认</a> {{^}}
<a class="btn btn-transparent btn-action list_for_default " style="color:blue" title="设置默认" href="javascript:void(0);" data-id="{{id}}">设置</a>{{/if_eq}}</td>
<td>{{weight}}</td>
<td>
{{#if_eq is_system '1'}}
系统默认
系统自带
{{^}}
<a class="btn btn-transparent btn-action list_for_edit" title="编辑看板" href="javascript:void(0);" data-id="{{id}}">
<i class="fa fa-pencil-square-o"></i>
</a>
<a class="btn btn-transparent btn-action list_for_delete" title="删除看板" class="list_for_delete" data-id="{{id}}" href="javascript:void(0)">
<i class="fa fa-trash-o"></i>
</a>
<a class="btn btn-transparent btn-action list_for_edit" title="编辑看板" href="javascript:void(0);" style="color:blue" data-id="{{id}}">
<i class="fa fa-pencil-square-o"></i>
</a>
<a class="btn btn-transparent btn-action list_for_delete" title="删除看板" class="list_for_delete" style="color:blue" data-id="{{id}}" href="javascript:void(0)">
<i class="fa fa-trash-o"></i>
</a>
{{/if_eq}}
</td>
Expand Down Expand Up @@ -398,6 +400,7 @@
<th>#</th>
<th>名称</th>
<th>数据范围</th>
<th>是否默认</th>
<th>排序权重</th>
<th>操作</th>
</tr>
Expand Down Expand Up @@ -872,6 +875,7 @@
var $board = null;
var $board_setting = null;
var _current_columns = [];
var _board_default_id = <?=board_default_id?>;
$(function () {
Expand Down Expand Up @@ -923,12 +927,16 @@
$('#range_container div').addClass('hide');
$('#range-'+range_value).removeClass(('hide'));
});
if (_active_sprint_id != '') {
window.$board.fetchBoardById(1);
if(_board_default_id>0){
if (_active_sprint_id != '') {
window.$board.fetchBoardById(1);
}else{
window.$board.fetchBoardById(2);
}
}else{
window.$board.fetchBoardById(2);
window.$board.fetchBoardById(_board_default_id);
}
//$('.selectpicker').selectpicker();
$("#boards_select").change(function () {
console.log($(this).val());
Expand Down
26 changes: 25 additions & 1 deletion public/dev/js/agile/board_setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,34 @@ var BoardSetting = (function () {
$(".list_for_delete").bind("click", function () {
BoardSetting.prototype.delete($(this).data('id'));
});

$(".list_for_edit").bind("click", function () {
BoardSetting.prototype.showEditBoardById($(this).data('id'));
});
$(".list_for_default").bind("click", function () {
BoardSetting.prototype.setDefault($(this).data('id'));
});
},
error: function (res) {
notify_error("请求数据错误" + res);
}
});
};

BoardSetting.prototype.setDefault = function (board_id) {
var params = { format: 'json' };
var project_id = window._cur_project_id;
//loading.show('#board_add_form', '正在处理');
$.ajax({
type: "POST",
dataType: "json",
async: true,
url: root_url + 'agile/setBoardDefault',
data: { id: board_id, project_id: project_id },
success: function (resp) {
auth_check(resp);
loading.closeAll();
notify_success(resp.msg);
BoardSetting.prototype.fetchBoards();
},
error: function (res) {
notify_error("请求数据错误" + res);
Expand Down
2 changes: 1 addition & 1 deletion public/dev/js/issue/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ var IssueMain = (function () {
}
if (resp.ret == '200') {
notify_success(resp.msg);
//window.location.reload();
window.location.reload();
} else {
notify_error(resp.msg);
}
Expand Down

0 comments on commit d497a69

Please sign in to comment.