Skip to content

Commit

Permalink
Merge pull request #251 from humhub/enh/241-permalinks-in-tasks-overview
Browse files Browse the repository at this point in the history
Permalinks in tasks overview
  • Loading branch information
luke- authored Feb 5, 2024
2 parents d458628 + 34fa328 commit d8b4d5a
Show file tree
Hide file tree
Showing 15 changed files with 260 additions and 144 deletions.
21 changes: 18 additions & 3 deletions controllers/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use humhub\modules\stream\actions\StreamEntryResponse;
use humhub\modules\tasks\helpers\TaskUrl;
use humhub\modules\tasks\widgets\TaskDetails;
use humhub\modules\user\models\User;
use humhub\modules\content\components\ContentContainerControllerAccess;
use humhub\modules\space\models\Space;
Expand Down Expand Up @@ -172,12 +173,26 @@ public function actionView($id)
throw new HttpException(403);
}

return $this->render("task", [
'task' => $task,
'contentContainer' => $this->contentContainer
return $this->render('task', [
'task' => $task
]);
}

public function actionLoadAjaxTask($id)
{
$task = Task::find()->contentContainer($this->contentContainer)->where(['task.id' => $id])->one();

if(!$task) {
throw new HttpException(404);
}

if(!$task->content->canView()) {
throw new HttpException(403);
}

return TaskDetails::widget(['task' => $task]);
}

public function actionModal($id, $cal)
{
$task = $this->getTaskById($id);
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
-------------------------
- Fix #249: Fix replaced method `friendship\Module::isEnabled()`
- Enh #229: Disable main navigation by default
- Enh #241: Integrate wall entry context menu for task on details and list pages

1.8.4 (December 21, 2023)
-------------------------
Expand Down
10 changes: 8 additions & 2 deletions helpers/TaskUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class TaskUrl extends Url
{
const ROUTE_VIEW_TASK = '/tasks/task/view';
const ROUTE_VIEW_TASK_MODAL = '/tasks/task/modal';
const ROUTE_RELOAD_TASK = '/tasks/task/load-ajax-task';

const ROUTE_DELETE_TASK = '/tasks/task/delete';
const ROUTE_EDIT_TASK = '/tasks/task/edit';
Expand Down Expand Up @@ -74,16 +75,21 @@ public static function exportXlsx($container = null)
return static::toRoute([static::ROUTE_EXPORT, 'format' => 'xlsx', 'container' => $container]);
}

public static function viewTask(Task $task)
public static function viewTask(Task $task, $scheme = false)
{
return static::container($task)->createUrl(static::ROUTE_VIEW_TASK, ['id' => $task->id]);
return static::container($task)->createUrl(static::ROUTE_VIEW_TASK, ['id' => $task->id], $scheme);
}

public static function viewTaskModal(Task $task, $cal = null)
{
return static::container($task)->createUrl(static::ROUTE_VIEW_TASK_MODAL, ['id' => $task->id, 'cal' => $cal]);
}

public static function reloadTask(Task $task)
{
return static::container($task)->createUrl(static::ROUTE_RELOAD_TASK, ['id' => $task->id]);
}

public static function deleteTask(Task $task, $cal = null, $redirect = null)
{
return static::container($task)->createUrl(static::ROUTE_DELETE_TASK, ['id' => $task->id,'cal' => $cal, 'redirect' => $redirect]);
Expand Down
2 changes: 1 addition & 1 deletion resources/css/task.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/css/task.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion resources/css/task.less
Original file line number Diff line number Diff line change
Expand Up @@ -706,4 +706,13 @@
.wall-entry-task h1 {
font-size: 14px;
font-weight: 500;
}
}

.nav-pills.task-preferences {
position: inherit;
top: 0;
left: 0;
.dropdown .dropdown-toggle i {
font-weight: normal;
}
}
18 changes: 18 additions & 0 deletions resources/js/humhub.task.list.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,24 @@ humhub.module('task.list', function (module, require, $) {
});
};

Task.prototype.reloadEntry = function (entry) {
if (!entry) {
return;
}

var row = entry.parent('div.task-list-item');
row.loader();

return client.get(row.$.data('reload-url')).then(function (response) {
row.$.html($(response.response).html());
return response;
}).catch(function (err) {
module.log.error(err, true);
}).finally(function () {
row.loader(false);
});
}

Task.prototype.isCompleted = function () {
return this.isStatus(STATUS_COMPLETED);
};
Expand Down
24 changes: 7 additions & 17 deletions views/task/task.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
*/

use humhub\modules\tasks\assets\Assets;
use humhub\modules\tasks\helpers\TaskUrl;
use humhub\modules\tasks\models\Task;
use humhub\modules\tasks\widgets\lists\TaskListDetails;
use humhub\modules\tasks\widgets\TaskDetails;
use humhub\modules\tasks\widgets\TaskHeader;
use humhub\modules\tasks\widgets\TaskSubMenu;
use humhub\modules\ui\view\components\View;

/* @var $this \humhub\modules\ui\view\components\View */
/* @var $task \humhub\modules\tasks\models\Task */
/* @var $contentContainer \humhub\modules\content\components\ContentContainerActiveRecord */
/* @var $this View */
/* @var $task Task */

Assets::register($this);

Expand All @@ -25,17 +28,4 @@
?>
<?= TaskHeader::widget() ?>
<?= TaskSubMenu::widget() ?>
<div id="task-container" class="panel panel-default task-details">

<?= $this->render('task_header', [
'canEdit' => $task->content->canEdit(),
'contentContainer' => $contentContainer,
'task' => $task
]); ?>

<div class="panel-body task-list-items">
<div class="cleafix task-list-item">
<?= TaskListDetails::widget(['task' => $task])?>
</div>
</div>
</div>
<?= TaskDetails::widget(['task' => $task]) ?>
15 changes: 7 additions & 8 deletions views/task/task_header.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,24 @@
use humhub\modules\tasks\widgets\TaskUserList;
use humhub\modules\ui\icon\widgets\Icon;

/* @var $contentContainer \humhub\modules\content\components\ContentContainerActiveRecord */
/* @var $task \humhub\modules\tasks\models\Task */
/* @var $canEdit boolean */
/* @var $collapse boolean */
/* @var $task Task */

$icon = 'fa-tasks';
$participantStyle = 'display:inline-block;';
$color = $task->getColor() ? $task->getColor() : $this->theme->variable('info');

?>
<div class="panel-heading clearfix">
<div class="pull-right">
<?= TaskContextMenu::widget(['task' => $task]) ?>
</div>

<div class="task-head">
<div>
<div class="task-list-item-title">
<strong><?= Icon::get($icon)->color($color)?> <?= Html::encode($task->title) ?></strong>
</div>
</div>

<?= TaskContextMenu::widget(['task' => $task, 'contentContainer' => $contentContainer]) ?>

<div class="row clearfix">
<div class="col-sm-12 media">
<div class="media-body clearfix">
Expand Down Expand Up @@ -96,4 +95,4 @@
</div>
</div>
</div>
</div>
</div>
109 changes: 85 additions & 24 deletions widgets/TaskContextMenu.php
Original file line number Diff line number Diff line change
@@ -1,58 +1,119 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2018 HumHub GmbH & Co. KG
* @copyright Copyright (c) HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*
*/

namespace humhub\modules\tasks\widgets;

use humhub\libs\Html;
use humhub\modules\content\widgets\WallEntryControls;
use humhub\modules\tasks\helpers\TaskUrl;
use humhub\modules\tasks\models\Task;
use yii\base\Widget;
use humhub\modules\ui\menu\MenuLink;
use humhub\widgets\Link;
use Yii;

/**
* Widget for rendering the menue buttons for a Task.
* Widget for rendering the menu buttons for a Task.
* @author davidborn
*/
class TaskContextMenu extends Widget
class TaskContextMenu extends WallEntryControls
{
/**
* @inheritdoc
*/
public $template = 'taskContextMenu';

public ?Task $task = null;

public string $mode = 'details';

public ?string $align = null;

/**
* @var Task
* @inheritdoc
*/
public $task;
public function beforeRun()
{
return parent::beforeRun() && $this->task->content->canEdit();
}

/**
* @var \humhub\modules\content\components\ContentContainerActiveRecord Current content container.
* @inheritdoc
*/
public $contentContainer;
public function init()
{
$this->object = $this->task;
$this->wallEntryWidget = new WallEntry(['model' => $this->task]);

parent::init();
}

/**
* @var boolean Determines if the user has write permissions.
* @inheritdoc
*/
public $canEdit;
public function getAttributes()
{
$attrs = parent::getAttributes();
Html::addCssClass($attrs, 'task-preferences');
return $attrs;
}

/**
* @inheritdoc
*/
public function run()
protected function getViewParams()
{
$params = parent::getViewParams();
$params['toggler'] = $this->getToggler();
$params['task'] = $this->task;
return $params;
}

public function initControls()
{
if(!$this->task->content->canEdit()) {
return '';
$this->renderOptions->disableControlsEntryEdit();
$this->renderOptions->disableControlsEntryDelete();
$this->renderOptions->disableControlsEntryPin();

if ($this->task->content->canEdit()) {
$this->addEntry(new MenuLink([
'label' => Yii::t('TasksModule.base', 'Edit'),
'url' => '#',
'icon' => 'pencil',
'sortOrder' => 100,
'htmlOptions' => [
'data-action-click' => 'ui.modal.post',
'data-action-click-url' => TaskUrl::editTask($this->task),
],
]));

$this->addEntry(new MenuLink([
'label' => Yii::t('TasksModule.base', 'Delete'),
'url' => '#',
'icon' => 'trash',
'sortOrder' => 300,
'htmlOptions' => [
'data-action-click' => 'ui.modal.post',
'data-action-click-url' => TaskUrl::deleteTask($this->task),
'data-action-confirm-header' => Yii::t('TasksModule.base', '<strong>Confirm</strong> task deletion'),
'data-action-confirm' => Yii::t('TasksModule.base', 'Do you really want to delete this task?'),
'data-action-confirm-text' => Yii::t('TasksModule.base', 'Delete')
],
]));
}

return $this->render('taskMenuDropdown', [
'deleteUrl' => TaskUrl::deleteTask($this->task, null, 1),
'editUrl' => TaskUrl::editTask($this->task, null, 1),
'task' => $this->task,
'extensionRequestUrl' => TaskUrl::requestExtension($this->task),
'resetUrl' => TaskUrl::resetTask($this->task),
'canEdit' => $this->task->content->canEdit(),
'canRequestExtension' => ( $this->task->schedule->canRequestExtension()),
'canReset' => $this->task->canResetTask()
]);
parent::initControls();
}

private function getToggler(): Link
{
if ($this->mode === 'details') {
return Link::asLink('<span class="caret"></span>')->icon('cog');
}

return Link::asLink()->icon('ellipsis-v');
}
}
Loading

0 comments on commit d8b4d5a

Please sign in to comment.