- Added MoveContent controller logic

- Enabled MoveContent for content type Post
- Fixed: Wrong page title displayed
This commit is contained in:
buddh4 2018-07-01 02:38:46 +02:00
parent f7ed7021bf
commit 104ce26391
16 changed files with 289 additions and 63 deletions

View File

@ -51,29 +51,13 @@ humhub.module('activity', function (module, require, $) {
var ActivityStream = stream.Stream.extend(function (container, options) {
var that = this;
stream.Stream.call(this, container, {
loadInitialCount: STREAM_INIT_COUNT,
initLoadCount: STREAM_INIT_COUNT,
loadCount: STREAM_LOAD_COUNT,
streamEntryClass: ActivityStreamEntry,
});
});
/*ActivityStream.prototype.showLoader = function () {
var $loaderListItem = $('<li id="activityLoader" class="streamLoader">');
loader.append($loaderListItem);
this.$content.append($loaderListItem);
};
ActivityStream.prototype.hideLoader = function () {
this.$content.find('#activityLoader').remove();
};*/
/*ActivityStream.prototype.onChange = function () {
if (!this.hasEntries()) {
this.$.html('<div id="activityEmpty"><div class="placeholder">' + module.text('activityEmpty') + '</div></div>');
}
};*/
ActivityStream.prototype.initScroll = function () {
if(!this.$content.is(':visible')) {
return;
@ -83,6 +67,9 @@ humhub.module('activity', function (module, require, $) {
var scrolling = true;
var that = this;
this.$content.scroll(function (evt) {
if(that.lastEntryLoaded()) {
return;
}
// save height of the overflow container
var _containerHeight = that.$content.height();
// save scroll height

View File

@ -470,7 +470,7 @@ class ContentActiveRecord extends ActiveRecord implements ContentOwner, Movable
public function canMove(ContentContainerActiveRecord $container = null)
{
if(!$this->canMove) {
return Yii::t('ContentModel.base', 'This content type can\'t be moved');
return Yii::t('ContentModule.base', 'This content type can\'t be moved');
}
return true;

View File

@ -82,6 +82,11 @@ class ContentContainerModuleManager extends \yii\base\Component
*/
public function isEnabled($id)
{
// Workaround for core post module
if($id === 'post') {
return true;
}
return in_array($id, $this->getEnabled());
}

View File

@ -8,6 +8,8 @@
namespace humhub\modules\content\controllers;
use humhub\libs\Html;
use humhub\modules\content\models\forms\MoveContentForm;
use Yii;
use yii\web\HttpException;
use humhub\components\Controller;
@ -31,7 +33,7 @@ class ContentController extends Controller
{
return [
'acl' => [
'class' => \humhub\components\behaviors\AccessControl::className(),
'class' => \humhub\components\behaviors\AccessControl::class,
]
];
}
@ -267,6 +269,27 @@ class ContentController extends Controller
return $this->asJson($json);
}
public function actionMove($id)
{
$form = new MoveContentForm(['id' => $id]);
if(!$form->content) {
throw new HttpException(404);
}
if($form->load(Yii::$app->request->post()) && $form->save()) {
return $this->asJson([
'success' => true,
'id' => $id,
'target' => $form->getTargetContainer()->id,
'message' => Yii::t('ContentModule.base', 'Content has been moved to {spacename}', ['spacename' => Html::encode($form->getTargetContainer()->getDisplayName())])
]);
}
return $this->renderAjax('moveModal', ['model' => $form]);
}
}
?>

View File

@ -412,7 +412,7 @@ class Content extends ContentDeprecated implements Movable
// Check for legacy modules
if(!$model->getModuleId()) {
return Yii::t('ContentModel.base', 'This content type can\'t be moved due to a missing module-id setting.');
return Yii::t('ContentModule.base', 'This content type can\'t be moved due to a missing module-id setting.');
}
if(!$container) {
@ -424,27 +424,27 @@ class Content extends ContentDeprecated implements Movable
if(!$container->moduleManager->isEnabled($model->getModuleId())) {
$module = Yii::$app->getModule($model->getModuleId());
$moduleName = ($module instanceof ContentContainerModule) ? $module->getContentContainerName($container) : $module->getName();
return Yii::t('ContentModel.base', 'The module {moduleName} is not enabled on the selected target space.', ['moduleName' => $moduleName]);
return Yii::t('ContentModule.base', 'The module {moduleName} is not enabled on the selected target space.', ['moduleName' => $moduleName]);
}
// Check if the current user is allowed to move this content at all
if(!$isContentOwner && !$this->container->can(ManageContent::class)) {
return Yii::t('ContentModel.base', 'You do not have the permission to move this content.');
return Yii::t('ContentModule.base', 'You do not have the permission to move this content.');
}
// Check if the current user is allowed to move this content to the given target space
if(!$isContentOwner && !$container->can(ManageContent::class)) {
return Yii::t('ContentModel.base', 'You do not have the permission to move this content to the given space.');
return Yii::t('ContentModule.base', 'You do not have the permission to move this content to the given space.');
}
// Check if the content owner is allowed to create content on the target space
$ownerPermissions = $container->getPermissionManager($this->createdBy);
if($this->isPrivate() && !$ownerPermissions->can(CreatePrivateContent::class)) {
return Yii::t('ContentModel.base', 'The author of this content is not allowed to create private content within the selected space.');
return Yii::t('ContentModule.base', 'The author of this content is not allowed to create private content within the selected space.');
}
if($this->isPublic() && !$ownerPermissions->can(CreatePublicContent::class)) {
return Yii::t('ContentModel.base', 'The author of this content is not allowed to create public content within the selected space.');
return Yii::t('ContentModule.base', 'The author of this content is not allowed to create public content within the selected space.');
}
return true;

View File

@ -0,0 +1,93 @@
<?php
namespace humhub\modules\content\models\forms;
use Yii;
use yii\base\Model;
use humhub\modules\content\models\Content;
use humhub\modules\space\models\Space;
/**
* Created by PhpStorm.
* User: kingb
* Date: 30.06.2018
* Time: 23:25
*/
class MoveContentForm extends Model
{
public $id;
/**
* @var Content
*/
public $content;
/**
* @var []
*/
public $target;
/**
* @var Space
*/
protected $targetContainer;
/**
* @inheritdoc
*/
public function init()
{
$this->content = Content::findOne(['id' => $this->id]);
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['target'], 'validateTarget']
];
}
public function validateTarget($attribute, $params, $validator)
{
$targetContainer = $this->getTargetContainer();
if(!$targetContainer) {
$this->addError($attribute, Yii::t('ContentModule.base', 'Invalid space selection.'));
} else {
$result = $this->content->canMove($targetContainer);
if($result !== true) {
$this->addError($attribute, $result);
}
}
}
/**
* @return Space|null
*/
public function getTargetContainer()
{
if(!$this->targetContainer) {
$target = isset($this->target[0]) ? $this->target[0] : null;
if($target) {
$this->targetContainer = Space::findOne(['guid' => $target]);
}
}
return $this->targetContainer;
}
public function save()
{
if(!$this->validate()) {
return false;
}
$this->content->move($this->getTargetContainer());
return true;
}
}

View File

@ -117,6 +117,18 @@ humhub.module('content', function (module, require, $) {
});
};
var submitMove = function(evt) {
debugger;
modal.submit(evt).then(function(response) {
if(response.success) {
if(response.message) {
module.log.success(response.message);
}
event.trigger('humhub:content:afterMove', response);
}
});
};
var templates = {
permalinkBody: '<div class="clearfix"><textarea rows="3" class="form-control permalink-txt" spellcheck="false" readonly>{permalink}</textarea><p class="help-block pull-right"><a href="#" data-action-click="copyToClipboard" data-action-target=".permalink-txt"><i class="fa fa-clipboard" aria-hidden="true"></i> {info}</a></p></div>',
permalinkFooter: '<button data-modal-close class="btn btn-default">{buttonClose}</button><a href="{permalink}" class="btn btn-primary" data-ui-loader>{buttonOpen}</a>'
@ -124,6 +136,7 @@ humhub.module('content', function (module, require, $) {
module.export({
Content: Content,
templates: templates
templates: templates,
submitMove: submitMove
});
});

View File

@ -0,0 +1,22 @@
<?php
use humhub\widgets\ModalDialog;
use yii\bootstrap\ActiveForm;
use humhub\modules\space\widgets\SpacePickerField;
use humhub\widgets\ModalButton;
use humhub\widgets\Button;
/* @var $model \humhub\modules\content\models\forms\MoveContentForm */
?>
<?php ModalDialog::begin(['header' => Yii::t('ContentModule.base', '<strong>Move</strong> content')]) ?>
<?php $form = ActiveForm::begin() ?>
<div class="modal-body">
<?= $form->field($model, 'target')->widget(SpacePickerField::class, ['maxSelection' => 1])?>
</div>
<div class="modal-footer">
<?= Button::primary(Yii::t('base', 'Save'))->action('content.submitMove') ?>
<?= ModalButton::cancel() ?>
</div>
<?php ActiveForm::end() ?>
<?php ModalDialog::end() ?>

View File

@ -9,14 +9,13 @@
namespace humhub\modules\content\widgets;
use humhub\modules\content\permissions\ManageContent;
use yii\helpers\Url;
use humhub\modules\content\permissions\CreatePublicContent;
use Yii;
/**
* Visibility link for Wall Entries can be used to switch form public to private and vice versa.
* MoveLink used to move a wallentry to another space.
*
* @package humhub.modules_core.wall.widgets
* @since 1.2
* @since 1.3
*/
class MoveLink extends WallEntryControlLink
{
@ -24,27 +23,38 @@ class MoveLink extends WallEntryControlLink
/**
* @var \humhub\modules\content\components\ContentActiveRecord
*/
public $contentRecord;
public $model;
/**
* @inheritdoc
* @inheritdocs
*/
public function run()
public $icon = 'fa-arrows-h';
/**
* @inheritdocs
*/
public $action = 'ui.modal.load';
/**
* @inheritdocs
*/
public function getLabel()
{
$content = $this->contentRecord->content;
$contentContainer = $content->container;
return Yii::t('ContentModule.base', 'Move content');
}
if($this->contentObject->isOwner() && $contentContainer->can(ManageContent::class)) {
return '';
}
/**
* @inheritdocs
*/
public function getActionUrl() {
return $this->model->content->container->createUrl('/content/content/move', ['id' => $this->model->content->id]);
}
$this->action = 'move';
$this->actionUrl = $contentContainer->createUrl(['']);
return $this->render('moveLink', [
'content' => $content,
'toggleLink' => Url::to(['/content/content/toggle-visibility', 'id' => $content->id])
]);
/**
* @inheritdocs
*/
public function preventRender()
{
return !$this->model->isOwner() || !$this->model->content->container->can(ManageContent::class);
}
}

View File

@ -183,15 +183,18 @@ class WallEntry extends Widget
public function getContextMenu()
{
$result = [];
$this->addControl($result, [DeleteLink::class, ['content' => $this->contentObject], ['sortOrder' => 100]]);
if (!empty($this->getEditUrl())) {
$this->addControl($result, [EditLink::class, ['model' => $this->contentObject, 'mode' => $this->editMode, 'url' => $this->getEditUrl()], ['sortOrder' => 200]]);
}
$this->addControl($result, [DeleteLink::class, ['content' => $this->contentObject], ['sortOrder' => 100]]);
$this->addControl($result, [VisibilityLink::class, ['contentRecord' => $this->contentObject], ['sortOrder' => 250]]);
$this->addControl($result, [NotificationSwitchLink::class, ['content' => $this->contentObject], ['sortOrder' => 300]]);
$this->addControl($result, [PermaLink::class, ['content' => $this->contentObject], ['sortOrder' => 400]]);
$this->addControl($result, [PinLink::class, ['content' => $this->contentObject], ['sortOrder' => 500]]);
$this->addControl($result, [MoveLink::class, ['model' => $this->contentObject], ['sortOrder' => 550]]);
$this->addControl($result, [ArchiveLink::class, ['content' => $this->contentObject], ['sortOrder' => 600]]);
if(isset($this->controlsOptions['add'])) {

View File

@ -51,6 +51,14 @@ class WallEntryControlLink extends \humhub\components\Widget
$this->label = ArrayHelper::remove($this->options, 'label', 'Label');
}
if(!empty($this->getAction())) {
$this->options['data-action-click'] = $this->getAction();
}
if(!empty($this->getActionUrl())) {
$this->options['data-action-url'] = $this->getActionUrl();
}
ArrayHelper::remove($this->options, 'sortOrder');
parent::init();
}
@ -60,9 +68,39 @@ class WallEntryControlLink extends \humhub\components\Widget
*/
public function run()
{
if($this->preventRender()) {
return '';
}
return '<li>'.$this->renderLink().'</li>';
}
/**
* This function may contain validation logic as permission checks.
*
* @return bool true if this link should be rendered false if not
*/
public function preventRender()
{
return false;
}
/**
* @return string renders the actual link
*/
protected function renderLink()
{
return Html::a($this->renderLinkText(), '#', $this->options);
}
/**
* @return string renders the link text with icon
*/
protected function renderLinkText()
{
return ($this->icon) ? '<i class="fa '.$this->getIcon().'"></i> '.$this->getLabel() : $this->getLabel();
}
/**
* @return string link label
*/
@ -84,19 +122,21 @@ class WallEntryControlLink extends \humhub\components\Widget
}
/**
* @return string renders the actual link
* @return string|null action url
* @since 1.3
*/
protected function renderLink()
public function getActionUrl()
{
return Html::a($this->renderLinkText(), '#', $this->options);
return null;
}
/**
* @return string renders the link text with icon
* @return string|null link action
* @since 1.3
*/
protected function renderLinkText()
private function getAction()
{
return ($this->icon) ? '<i class="fa '.$this->getIcon().'"></i> '.$this->getLabel() : $this->getLabel();
return $this->action;
}
}

View File

@ -28,12 +28,21 @@ use humhub\modules\user\models\User;
*/
class Post extends ContentActiveRecord implements Searchable
{
/**
* @inheritdoc
*/
public $wallEntryClass = 'humhub\modules\post\widgets\WallEntry';
/**
* @inheritdoc
*/
public $moduleId = 'post';
/**
* @inheritdoc
*/
public $canMove = true;
/**
* @inheritdoc
*/

View File

@ -198,6 +198,10 @@ humhub.module('stream.Stream', function (module, require, $) {
return this.state.loading === true;
};
Stream.prototype.lastEntryLoaded = function () {
return this.state.lastEntryLoaded === true;
};
Stream.prototype.load = function (options) {
return new StreamRequest(this, options).load()
.then($.proxy(this.handleResponse, this))

View File

@ -21,6 +21,7 @@ humhub.module('stream.wall', function (module, require, $) {
var Filter = require('ui.filter').Filter;
var string = require('util').string;
var topic = require('topic');
var view = require('ui.view');
/**
* Stream implementation for main wall streams.
@ -43,9 +44,9 @@ humhub.module('stream.wall', function (module, require, $) {
WallStream.prototype.initEvents = function () {
var that = this;
this.on('humhub:stream:beforeLoadEntries', function () {
this.on('humhub:stream:beforeLoadEntries.wallStream', function () {
$('#btn-load-more').hide();
}).on('humhub:stream:afterAddEntries', function (evt, resp, res) {
}).on('humhub:stream:afterAddEntries.wallStream', function (evt, resp, res) {
$.each(resp.contentSuppressions, function (key, contentSuppression) {
var entry = that.entry(key);
if(entry) {
@ -57,13 +58,25 @@ humhub.module('stream.wall', function (module, require, $) {
if(!resp.isLast) {
$('#btn-load-more').show();
}
}).on('humhub:stream:lastEntryLoaded', function () {
}).on('humhub:stream:lastEntryLoaded.wallStream', function () {
$('#btn-load-more').hide();
});
event.on('humhub:content:newEntry', function (evt, html) {
event.on('humhub:content:newEntry.wallStream', function (evt, html) {
that.prependEntry(html, true);
});
event.on('humhub:content:afterMove.wallStream', function (evt, response) {
var entry = that.entry(response.id);
debugger;
if(entry) {
if(view.getState().moduleId === 'dashboard') {
entry.reload();
} else {
setTimeout($.proxy(entry.remove, entry), 1000);
}
}
});
};
WallStream.template = {
@ -119,7 +132,9 @@ humhub.module('stream.wall', function (module, require, $) {
};
var unload = function() {
debugger;
event.off('humhub:content:newEntry.wallStream');
event.off('humhub:content:afterMove.wallStream');
event.off('humhub:topic:added.wallStream');
event.off('humhub:topic:removed.wallStream');
event.off('humhub:topic:updated.wallStream');
@ -263,6 +278,7 @@ humhub.module('stream.wall', function (module, require, $) {
module.export({
WallStream: WallStream,
WallStreamFilter: WallStreamFilter
WallStreamFilter: WallStreamFilter,
unload: unload
});
});

View File

@ -8,7 +8,7 @@
namespace humhub\modules\ui\filter\widgets;
use humhub\widgets\BasePickerField;
use humhub\modules\ui\form\widgets\BasePicker;
use yii\helpers\ArrayHelper;
class PickerFilterInput extends FilterInput
@ -25,7 +25,7 @@ class PickerFilterInput extends FilterInput
public $pickerOptions = [];
public $picker = BasePickerField::class;
public $picker = BasePicker::class;
/**
* @var string data-action-click handler of the input event

View File

@ -15,8 +15,9 @@ humhub.module('ui.view', function (module, require, $) {
};
var setState = function (moduleId, controlerId, action) {
debugger;
state = {
title: title || document.title,
title: document.title,
moduleId: moduleId,
controllerId: controlerId,
action: action
@ -33,7 +34,7 @@ humhub.module('ui.view', function (module, require, $) {
module.initOnPjaxLoad = true;
var init = function ($pjax) {
title = document.title;
//title = document.title;
module.log.debug('Current view state', state);
};