Skip to content

Commit

Permalink
Merge pull request #53 from funktechno/dev
Browse files Browse the repository at this point in the history
0.3.2 release
  • Loading branch information
lastlink authored Nov 12, 2022
2 parents 12ebf93 + 34e8401 commit f3395df
Show file tree
Hide file tree
Showing 12 changed files with 332 additions and 28 deletions.
1 change: 1 addition & 0 deletions .github/issue_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This issue is:
### Configuration

- Kanboard version:
- Plugin version:
- Database type and version:
- PHP version:
- OS:
Expand Down
4 changes: 2 additions & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

* [ ] Have you updated the ChangeLog with your proposed changes?
* [ ] Have you checked to ensure there aren't other open [Pull Requests](../../pulls) for the same update/change?
* [ ] Have you updated the getPluginVersion() in Plugin.php and Makefile version appropriately?

* pr update to master branch
* [ ] Have you updated the getPluginVersion() in Plugin.php and Makefile version appropriately?
### New Feature Submissions:

* [ ] Have you added an explanation of what your changes do and why you'd like us to include them?
Expand Down
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Version 0.3.2
Improvements:

* width updates to wiki table list
* public mode
* initialize notifications(?) maybe works
* some syntax error fixes

Version 0.3.1-alpha

Bug fixes:
Expand Down
62 changes: 61 additions & 1 deletion Controller/WikiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Kanboard\Plugin\Wiki\Controller;

use Kanboard\Controller\BaseController;
use Kanboard\Core\Controller\AccessForbiddenException;

/**
* Wiki
Expand Down Expand Up @@ -53,6 +54,24 @@ public function index()
)));
}

public function readonly()
{
$token = $this->request->getStringParam('token');
$project = $this->projectModel->getByToken($token);

if (empty($project)) {
throw AccessForbiddenException::getInstance()->withoutLayout();
}

$this->response->html($this->helper->layout->app('wiki:wiki/show', array(
'project' => $project,
'no_layout' => true,
'not_editable' => true,
'title' => $project['name'] .= " ". t('Wiki'),
'wikipages' => $this->wiki->getWikipages($project['id']),
), 'wiki:wiki/sidebar'));
}

/**
* list for wikipages for a project
*/
Expand All @@ -66,7 +85,7 @@ public function show()

$this->response->html($this->helper->layout->app('wiki:wiki/show', array(
'project' => $project,
'title' => t('Wiki'),
'title' => $project['name'] .= " ". t('Wiki'),
'wikipages' => $this->wiki->getWikipages($project['id']),
), 'wiki:wiki/sidebar'));

Expand Down Expand Up @@ -117,12 +136,53 @@ public function edit(array $values = array(), array $errors = array())
), 'wiki:wiki/sidebar'));
}

public function detail_readonly() {
$token = $this->request->getStringParam('token');

$project = $this->projectModel->getByToken($token);

if (empty($project)) {
throw AccessForbiddenException::getInstance()->withoutLayout();
}
$wiki_id = $this->request->getIntegerParam('wiki_id');

$wikipages = $this->wiki->getWikipages($project['id']);

foreach ($wikipages as $page) {
if (t($wiki_id) == t($page['id'])) {
$wikipage = $page;
break;
}
}

// If the last wikipage was deleted, select the new last wikipage.
if (!isset($wikipage)) {
$wikipage = end($wikipages);
}

// use a wiki helper for better side bar TODO:
$this->response->html($this->helper->layout->app('wiki:wiki/detail', array(
'project' => $project,
'title' => t('Wikipage'),
'wiki_id' => $wiki_id,
'wiki' => $wikipage,
'no_layout' => true,
'not_editable' => true,
'files' => $this->wikiFile->getAllDocuments($wiki_id),
'images' => $this->wikiFile->getAllImages($wiki_id),
// 'wikipage' => $this->wiki->getWikipage($wiki_id),
'wikipage' => $wikipage,
'wikipages' => $wikipages,
), 'wiki:wiki/sidebar'));
}

/**
* details for single wiki page
*/
public function detail()
{
$project = $this->getProject();

$wiki_id = $this->request->getIntegerParam('wiki_id');

$wikipages = $this->wiki->getWikipages($project['id']);
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugin=Wiki
version=0.3.1
version=0.3.2
all:
@ echo "Build archive for plugin ${plugin} version=${version}"
@ git archive HEAD --prefix=${plugin}/ --format=zip -o ${plugin}-${version}.zip
21 changes: 21 additions & 0 deletions Model/Wiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Kanboard\Plugin\Wiki\Model;

use Kanboard\Core\Base;
use Kanboard\Core\Controller\PageNotFoundException;
use Kanboard\Core\Controller\AccessForbiddenException;
// use Kanboard\Model\WikiModel;
use Kanboard\Model\UserModel;
use SimpleValidator\Validator;
Expand Down Expand Up @@ -41,6 +43,15 @@ public function getEditions($wiki_id)
* @var string
*/
const WIKITABLE = 'wikipage';

/**
* Events
*
* @var string
*/
const EVENT_UPDATE = 'wikipage.update';
const EVENT_CREATE = 'wikipage.create';
const EVENT_DELETE = 'wikipage.delete';
/**
* Get all Wiki Pages by order for a project
*
Expand Down Expand Up @@ -216,6 +227,11 @@ public function updatepage($paramvalues, $editions, $date = '')
if ($this->userSession->isLogged()) {
$values['modifier_id'] = $this->userSession->getId();
}

$wikiEventJob = new WikiEventJob($this->container);
$wikiEventJob->executeWithId($paramvalues['id'], self::EVENT_DELETE);
// $wikiEventJob = new WikiEventJob($this->container);
// $wikiEventJob->execute($paramvalues['title'], $paramvalues['project_id'], $values, self::EVENT_UPDATE);
$this->db->table(self::WIKITABLE)->eq('id', $paramvalues['id'])->update($values);

return (int) $paramvalues['id'];
Expand Down Expand Up @@ -249,6 +265,9 @@ public function createpage($project_id, $title, $content, $date = '', $order = n
// $values['creator_id'] = $this->userSession->getId();
// $values['modifier_id'] = $this->userSession->getId();
// date_modification
// TODO notification
$wikiEventJob = new WikiEventJob($this->container);
$wikiEventJob->execute($title, $project_id, $values, self::EVENT_CREATE);

return $this->db->table(self::WIKITABLE)->persist($values);

Expand Down Expand Up @@ -380,6 +399,8 @@ public function validatePageUpdate(array $values)
*/
public function removepage($wiki_id)
{
$wikiEventJob = new WikiEventJob($this->container);
$wikiEventJob->executeWithId($wiki_id, self::EVENT_DELETE);
return $this->db->table(self::WIKITABLE)->eq('id', $wiki_id)->remove();
}
/**
Expand Down
120 changes: 120 additions & 0 deletions Model/WikiEventBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php

namespace Kanboard\Plugin\Wiki\Model;

use Kanboard\EventBuilder\BaseEventBuilder;
use Kanboard\Event\CommentEvent;

/**
* Class WikiEventBuilder
*
* @package Kanboard\EventBuilder
*/
class WikiEventBuilder extends BaseEventBuilder
{
protected $wiki_id = 0;

protected $title = "";

protected $projectId = 0;

/**
* Set wiki_id
*
* @param int $wiki_id
* @return $this
*/
public function withPageId($wiki_id)
{
$this->wiki_id = $wiki_id;
return $this;
}
/**
* @param string $title
* @param int $projectId
* @return $this
*/
public function withTitle($title, $projectId)
{
$this->title = $title;
$this->projectId = $projectId;
return $this;
}

/**
* Build event data
*
* @access public
* @return CommentEvent|null
*/
public function buildEvent()
{
$wikiPage = $this->wiki->getWikipage($this->wiki_id);

if (empty($wikiPage)) {
return null;
}

return new CommentEvent(array(
'wiki' => $wikiPage,
'project' => $this->projectModel->getById($wikiPage['project_id']),
));
}

public function buildEventWiki($wikiPage)
{
if (empty($wikiPage)) {
return null;
}

return new CommentEvent(array(
'wiki' => $wikiPage,
'project' => $this->projectModel->getById($wikiPage['project_id']),
));
}

/**
* Get event title with author
*
* @access public
* @param string $author
* @param string $eventName
* @param array $eventData
* @return string
*/
public function buildTitleWithAuthor($author, $eventName, array $eventData)
{
switch ($eventName) {
case Wiki::EVENT_UPDATE:
return e('%s updated a wikipage on the project #%d', $author, $eventData['project']['id']);
case Wiki::EVENT_CREATE:
return e('%s created a wikipage on the project #%d', $author, $eventData['project']['id']);
case Wiki::EVENT_DELETE:
return e('%s removed a wikipage on the project #%d', $author, $eventData['project']['id']);
default:
return '';
}
}

/**
* Get event title without author
*
* @access public
* @param string $eventName
* @param array $eventData
* @return string
*/
public function buildTitleWithoutAuthor($eventName, array $eventData)
{
switch ($eventName) {
case Wiki::EVENT_CREATE:
return e('New wikipage on project #%d', $eventData['project']['task_id']);
case Wiki::EVENT_UPDATE:
return e('wikipage updated on project #%d', $eventData['project']['task_id']);
case Wiki::EVENT_DELETE:
return e('wikipage removed on project #%d', $eventData['project']['task_id']);
default:
return '';
}
}
}
66 changes: 66 additions & 0 deletions Model/WikiEventJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Kanboard\Plugin\Wiki\Model;

use Kanboard\Job\BaseJob;
// use Kanboard\EventBuilder\CommentEventBuilder;
// use Kanboard\Model\CommentModel;

/**
* Class WikiEventJob
*
* @package Kanboard\Job
*/
class WikiEventJob extends BaseJob
{
/**
* Set job params
*
* @param int $wikiPageId
* @param string $eventName
* @return $this
*/
public function withParams($wikiPageId, $eventName)
{
$this->jobParams = array($wikiPageId, $eventName);
return $this;
}

/**
* Execute job
*
* @param int $wikiPageId
* @param string $eventName
*/
public function execute($title, $projectId, $wikiPage, $eventName)
{
$event = WikiEventBuilder::getInstance($this->container)
->withTitle($title, $projectId)
->buildEventWiki($wikiPage);

if ($event !== null) {
$this->dispatcher->dispatch($eventName, $event);

// if ($eventName === Wiki::EVENT_CREATE) {
// $userMentionJob = $this->userMentionJob->withParams($event['comment']['comment'], Wiki::EVENT_USER_MENTION, $event);
// $this->queueManager->push($userMentionJob);
// }
}
}

public function executeWithId($wikiPageId, $eventName)
{
$event = WikiEventBuilder::getInstance($this->container)
->withPageId($wikiPageId)
->buildEvent();

if ($event !== null) {
$this->dispatcher->dispatch($eventName, $event);

// if ($eventName === Wiki::EVENT_CREATE) {
// $userMentionJob = $this->userMentionJob->withParams($event['comment']['comment'], Wiki::EVENT_USER_MENTION, $event);
// $this->queueManager->push($userMentionJob);
// }
}
}
}
4 changes: 2 additions & 2 deletions Model/WikiFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public function getProjectId($file_id)
return $this->db
->table(self::TABLE)
->eq(self::TABLE.'.id', $file_id)
->join(WikiModel::TABLE, 'id', 'wiki_id')
->findOneColumn(WikiModel::TABLE . '.project_id') ?: 0;
->join(Wiki::WIKITABLE, 'id', 'wiki_id')
->findOneColumn(Wiki::WIKITABLE . '.project_id') ?: 0;
}

/**
Expand Down
Loading

0 comments on commit f3395df

Please sign in to comment.