Skip to content

Commit

Permalink
Merge pull request #73 from funktechno/f/reorder_list
Browse files Browse the repository at this point in the history
progress on wiki page reorder persistance
  • Loading branch information
lastlink committed Jul 19, 2024
2 parents f48202a + a237d61 commit 3eb7522
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 16 deletions.
56 changes: 56 additions & 0 deletions Asset/Javascript/wiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,62 @@ jQuery(document).ready(function () {

// Don't do anything if dropping the same column we're dragging.
if (dragSrcEl != this) {

let targetRoute;
if(e.target.localName == "a"){
targetRoute = e.target.href
} else {
targetRoute = e.target.querySelector("a").href
}
let targetParams = new URL(targetRoute)
var targetProperties = {}
for (const [key, value] of targetParams.searchParams.entries()) {
targetProperties[key] = value
}
// console.log("targetProperties", targetProperties)

var srcParams = new URL(dragSrcEl.querySelector("a").href)
var srcProperties = {}

for (const [key, value] of srcParams.searchParams.entries()) {
srcProperties[key] = value
}
// console.log("srcProperties", srcProperties)

let project_id = srcProperties["project_id"]

// console.log("project_id", project_id)

let request = {
"src_wiki_id": srcProperties["wiki_id"],
"target_wiki_id": targetProperties["wiki_id"]
}

console.log("request", request)

$.ajax({
cache: false,
url: $("#columns").data("reorder-url"),
contentType: "application/json",
type: "POST",
processData: false,
data: JSON.stringify(request),
success: function(data) {
// self.refresh(data);
// self.savingInProgress = false;
},
error: function() {
// self.app.hideLoadingIcon();
// self.savingInProgress = false;
},
statusCode: {
403: function(data) {
window.alert(data.responseJSON.message);
document.location.reload(true);
}
}
});

// Set the source column's HTML to the HTML of the column we dropped on.
//alert(this.outerHTML);
//dragSrcEl.innerHTML = this.innerHTML;
Expand Down
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
Version 0.3.4
Improvements:

* ability to reorder wiki pages

Bug fixes:

* Fix https://github.com/funktechno/kanboard-plugin-wiki/issues/28

Version 0.3.3
Improvements:

Expand Down
53 changes: 53 additions & 0 deletions Controller/WikiAjaxController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Kanboard\Plugin\Wiki\Controller;

use Exception;
use Kanboard\Controller\BaseController;
use Kanboard\Core\Controller\AccessForbiddenException;
use Kanboard\Model\UserMetadataModel;

/**
* Class WikiAjaxController
*
* @package Kanboard\Controller
* @author lastlink
*/
class WikiAjaxController extends BaseController
{
/**
* reorder for wikipages using src and target page moving src before target
*/
public function reorder()
{
$this->checkReusableGETCSRFParam();
$project_id = $this->request->getIntegerParam('project_id');

if (! $project_id || ! $this->request->isAjax()) {
throw new AccessForbiddenException();
}

$values = $this->request->getJson();

if(!isset($values['src_wiki_id']) || !isset($values['target_wiki_id'])) {
throw new AccessForbiddenException();
}

// if (! $this->helper->projectRole->canMoveTask($project_id, $values['src_column_id'], $values['dst_column_id'])) {
// throw new AccessForbiddenException(e("You don't have the permission to move this task"));
// }

try {
$result = $this->wiki->reorderPages($project_id, $values['src_wiki_id'], $values['target_wiki_id']);

if (!$result) {
$this->response->status(400);
} else {
$this->response->status(200);
}
} catch (Exception $e) {
$this->response->html('<div class="alert alert-error">'.$e->getMessage().'</div>');
}
}

}
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.3
version=0.3.4
all:
@ echo "Build archive for plugin ${plugin} version=${version}"
@ git archive HEAD --prefix=${plugin}/ --format=zip -o ${plugin}-${version}.zip
56 changes: 47 additions & 9 deletions Model/Wiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,52 @@ public function getWikipages($project_id)
// ->findOne();
}

public function reorderPages($project_id, $src_wiki_id, $target_wiki_id){
// retrieve wiki pages
$wikiPages = $this->getWikipages($project_id);

// change order of each in for loop, move matching id to one before target
$orderColumn = 1;
$targetColumn = 1;
$oldSourceColumn = 1;
for ($i=0; $i < count($wikiPages); $i++) {
$oldOrderColumn = $wikiPages[$i]['ordercolumn'];
$id = $wikiPages[$i]['id'];
if($id == $target_wiki_id){
// add additional order column
$orderColumn++;
$targetColumn = $orderColumn;
}

if ($id == $src_wiki_id) {
$oldSourceColumn = $oldOrderColumn;
} else {
if ($oldOrderColumn != $orderColumn) {
$this->savePagePosition($id, $orderColumn);
}
$orderColumn++;
}
}

// update moved src
if($oldSourceColumn != $targetColumn -1){
$this->savePagePosition($src_wiki_id, $orderColumn);
}
}

public function savePagePosition($wiki_id, $orderColumn) {
$result = $this->db->table(self::WIKITABLE)->eq('id', $wiki_id)->update(array(
'ordercolumn' => $orderColumn
));

if (! $result) {
$this->db->cancelTransaction();
return false;
}

return true;
}



/**
Expand Down Expand Up @@ -229,7 +275,7 @@ public function updatepage($paramvalues, $editions, $date = '')
}

$wikiEventJob = new WikiEventJob($this->container);
$wikiEventJob->executeWithId($paramvalues['id'], self::EVENT_DELETE);
$wikiEventJob->executeWithId($paramvalues['id'], self::EVENT_UPDATE);
// $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);
Expand Down Expand Up @@ -421,14 +467,6 @@ public function restoreEdition($wiki_id, $edition)
->eq('wikipage_id', $wiki_id)
->findOne(); // this may possibly not support joins

// $values = array(
// 'title' => $editionvalues['title'],
// 'current_edition' => $edition,
// 'content' => $editionvalues['title'],
// 'date_modification' => $date ?: date('Y-m-d'),
// 'modifier_id' => $this->userSession->getId(),
// );

$values = [
'title' => $editionvalues['title'],
'current_edition' => $edition,
Expand Down
6 changes: 5 additions & 1 deletion Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Plugin extends Base
public function initialize()
{
$this->projectAccessMap->add('WikiController', '*', Role::PROJECT_MEMBER);
$this->projectAccessMap->add('WikiAjaxController', '*', Role::PROJECT_MEMBER);
$this->applicationAccessMap->add('WikiController', array('readonly','detail_readonly'), Role::APP_PUBLIC);
$this->projectAccessMap->add('WikiFileController', '*', Role::PROJECT_MEMBER);
$this->projectAccessMap->add('WikiFileViewController', '*', Role::PROJECT_MEMBER);
Expand Down Expand Up @@ -68,6 +69,9 @@ public function onStartup()
public function getClasses()
{
return array(
'Plugin\Wiki\Controller' => [
'WikiAjaxController'
],
'Plugin\Wiki\Model' => array(
'Wiki',
'WikiFile'
Expand All @@ -92,7 +96,7 @@ public function getPluginAuthor()

public function getPluginVersion()
{
return '0.3.3';
return '0.3.4';
}

public function getPluginHomepage()
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ Note that you can only restore **saved** editions. So you if you have the global
- [x] editions listing and restore
- Related issues: [#9](https://github.com/kanboard/kanboard/issues/9)
- [x] finish edit
- [] ordering
- [] drop down to switch
- [] drag to move, require css magic
- [x] ordering
- [x] drop down to switch
- [x] drag to move, require css magic
- [] subpages and pagination
- [x] fix wiki sidebar
- use html template render properly to list wiki pages
Expand Down
4 changes: 2 additions & 2 deletions Template/wiki/detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
</style>
<div class="clearfix">
<div class="sidebar column list">
<ul id="columns">
<ul id="columns" data-reorder-url="<?= $this->url->href('WikiAjaxController', 'reorder', array('plugin' => 'wiki', 'project_id' => $project['id'], 'csrf_token' => $this->app->getToken()->getReusableCSRFToken())) ?>">
<?php if (!empty($wikipages)): ?>
<?php foreach ($wikipages as $page): ?>

<li class="wikipage" <?php if (!$not_editable): ?>draggable="true"<?php endif ?>>
<li class="wikipage" data-project-id="<?=$project['id']?>" data-page-id="<?=$page['id']?>" <?php if (!$not_editable): ?>draggable="true"<?php endif ?>>
<?php if (!$not_editable): ?>
<?=$this->url->link(t($page['title']), 'WikiController', 'detail', array('plugin' => 'wiki', 'project_id' => $project['id'], 'wiki_id' => $page['id']))?>

Expand Down

0 comments on commit 3eb7522

Please sign in to comment.