Compare commits
2 Commits
9c6114cf86
...
296ad3a2ce
Author | SHA1 | Date | |
---|---|---|---|
296ad3a2ce | |||
4807b7d4ae |
10
README.md
10
README.md
@ -1,6 +1,16 @@
|
|||||||
# My Wiki
|
# My Wiki
|
||||||
Place this app in **nextcloud/apps/**
|
Place this app in **nextcloud/apps/**
|
||||||
|
|
||||||
|
|
||||||
|
## Disclaimer:
|
||||||
|
**This is not a real wiki**
|
||||||
|
This app allow me to display the folders where I organize some documentation within a browsable struture
|
||||||
|
Many things could be wrong (this is my first app for nextcloud), I would appreciate any comments/help
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Building the app
|
## Building the app
|
||||||
|
|
||||||
The app can be built by using the provided Makefile by running:
|
The app can be built by using the provided Makefile by running:
|
||||||
|
@ -1,3 +1,23 @@
|
|||||||
#hello {
|
#hello {
|
||||||
color: red;
|
color: red;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
li[data-id="wikis"] select {
|
||||||
|
width: calc(100% - 50px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.-myWikiControls {
|
||||||
|
width: 100%;
|
||||||
|
margin: .25em;
|
||||||
|
}
|
||||||
|
.-myWikiControls select {
|
||||||
|
width: 98%;
|
||||||
|
}
|
||||||
|
|
||||||
|
option.separator {
|
||||||
|
font-size: 1px;
|
||||||
|
min-height:1px;
|
||||||
|
max-height:1px;
|
||||||
|
padding:0;
|
||||||
|
background-color: #000000;
|
||||||
|
}
|
||||||
|
37
js/WikiDropdownHelper.js
Normal file
37
js/WikiDropdownHelper.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
class WikiDropdownHelper {
|
||||||
|
constructor(element) {
|
||||||
|
this.dd = element;
|
||||||
|
}
|
||||||
|
clear() {
|
||||||
|
while (this.dd.hasChildNodes()) {
|
||||||
|
this.dd.removeChild(this.dd.firstChild);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
add(text, value, set=false) {
|
||||||
|
var option = document.createElement("option");
|
||||||
|
option.text = text;
|
||||||
|
option.value = value;
|
||||||
|
this.dd.appendChild(option);
|
||||||
|
if ( set ) {
|
||||||
|
this.set(value);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
rename(value, text) {
|
||||||
|
this.dd.querySelector(`option[value="${value}"]`).innerHTML=text;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
get() {
|
||||||
|
return {
|
||||||
|
text:this.dd.parentElement.value,
|
||||||
|
value:this.dd.parentElement.text
|
||||||
|
};
|
||||||
|
}
|
||||||
|
set(value) {
|
||||||
|
this.dd.parentElement.value=value;
|
||||||
|
// this.onSelectWiki(value);
|
||||||
|
}
|
||||||
|
}
|
123
js/WikiNavigation.js
Normal file
123
js/WikiNavigation.js
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
class WikiNavigation {
|
||||||
|
dd = null;
|
||||||
|
onSelectWiki = null;
|
||||||
|
|
||||||
|
constructor(container, onSelectWiki){
|
||||||
|
let self = this;
|
||||||
|
this.container = container;
|
||||||
|
this.onSelectWiki = onSelectWiki;
|
||||||
|
|
||||||
|
let wikiSelector = container.getElementsByTagName('select')[0];
|
||||||
|
this.dd = new WikiDropdownHelper(wikiSelector);
|
||||||
|
wikiSelector.addEventListener('change', e=>{
|
||||||
|
if(self.onSelectWiki) {
|
||||||
|
self.onSelectWiki(+e.target.value||0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.loadWikis();
|
||||||
|
|
||||||
|
// Popup menu
|
||||||
|
let appNavigationMenu = container.getElementsByClassName('app-navigation-entry-menu')[0];
|
||||||
|
let button = container.querySelector('.app-navigation-entry-utils-menu-button button');
|
||||||
|
button.addEventListener('click', ()=>appNavigationMenu.classList.toggle("open") );
|
||||||
|
document.addEventListener('click', e=>{if(e.target!==button)appNavigationMenu.classList.remove("open");})
|
||||||
|
|
||||||
|
appNavigationMenu.querySelector('[data-id="add"]').addEventListener('click', ()=>self.wikiChooseFolder() );
|
||||||
|
appNavigationMenu.querySelector('[data-id="rename"]').addEventListener('click', ()=>self.wikiRename() );
|
||||||
|
appNavigationMenu.querySelector('[data-id="delete"]').addEventListener('click', ()=>self.wikiDelete() );
|
||||||
|
}
|
||||||
|
|
||||||
|
wikiRename() {
|
||||||
|
let self=this;
|
||||||
|
OC.dialogs.prompt(
|
||||||
|
t(appName, 'This allow you to rename the displayed name for the selected wiki. (The folder will remain unchanged)'),
|
||||||
|
t(appName, 'Rename Wiki'),
|
||||||
|
(ok,value)=>{
|
||||||
|
if(ok) {
|
||||||
|
value = value.trim();
|
||||||
|
if(value!='') {
|
||||||
|
let wiki = self.dd.get();
|
||||||
|
var baseUrl = OC.generateUrl('/apps/mywiki/wikis');
|
||||||
|
$.ajax({
|
||||||
|
url: baseUrl,
|
||||||
|
type: 'PUT',
|
||||||
|
contentType: 'application/json',
|
||||||
|
data: JSON.stringify({id:wiki.value, title:value})
|
||||||
|
}).done(function (response) {
|
||||||
|
console.info('JDG :: Wiki renamed', response);
|
||||||
|
// ToDo :: Rename in the dropdown
|
||||||
|
}).fail(function (response, code) {
|
||||||
|
OC.dialogs.alert('Error', t(appName,'Error renaming wiki'));
|
||||||
|
console.error('JDG :: Error renaming wiki', response);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
t(appName, 'New name:'),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
loadWikis() {
|
||||||
|
let self = this;
|
||||||
|
|
||||||
|
this.dd.clear().add(t(appName, 'Loading...'), '', true);
|
||||||
|
|
||||||
|
var baseUrl = OC.generateUrl('/apps/mywiki/wikis');
|
||||||
|
$.ajax({
|
||||||
|
url: baseUrl,
|
||||||
|
type: 'GET',
|
||||||
|
contentType: 'application/json'
|
||||||
|
}).done(function (response) {
|
||||||
|
console.info('JDG :: Wikis loaded', response);
|
||||||
|
self.dd.clear().add('','');
|
||||||
|
response.forEach( x=>self.dd.add(x.title, x.id) );
|
||||||
|
}).fail(function (response, code) {
|
||||||
|
OC.dialogs.alert('Error', t(appName,'Error getting the list of wikis'));
|
||||||
|
console.error('JDG :: Error getting the wikis', response);
|
||||||
|
self.dd.clear();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
wikiChooseFolder() {
|
||||||
|
let self = this;
|
||||||
|
this.dd.set('');
|
||||||
|
window.OC.dialogs.filepicker(
|
||||||
|
t(appName, 'Select Wiki folder'),
|
||||||
|
(path, type) => {
|
||||||
|
if (type === OC.dialogs.FILEPICKER_TYPE_CHOOSE) {
|
||||||
|
self.wikiAdd(path, path.split('/').pop());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
['httpd/unix-directory'],
|
||||||
|
true,
|
||||||
|
OC.dialogs.FILEPICKER_TYPE_CHOOSE,
|
||||||
|
'', // Path
|
||||||
|
{ allowDirectoryChooser: true }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
wikiAdd(folderPath, title) {
|
||||||
|
let self = this;
|
||||||
|
|
||||||
|
var baseUrl = OC.generateUrl('/apps/mywiki/wikis');
|
||||||
|
$.ajax({
|
||||||
|
url: baseUrl,
|
||||||
|
type: 'POST',
|
||||||
|
data: JSON.stringify({title:title, folderPath:folderPath}),
|
||||||
|
contentType: 'application/json'
|
||||||
|
}).done(function (response) {
|
||||||
|
console.info('JDG :: wikiAdd :: Wiki added', response);
|
||||||
|
if ( response.id>0 ) {
|
||||||
|
self.dd.add(response.title, response.id, true);
|
||||||
|
}
|
||||||
|
}).fail(function (response, code) {
|
||||||
|
OC.dialogs.alert('Error', t(appName,'It has not been possible to add the new wiki'));
|
||||||
|
console.error('JDG :: wikiAdd :: Error adding the wiki', response);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
54
js/script.js
54
js/script.js
@ -1,10 +1,55 @@
|
|||||||
|
const appName = 'MyWiki';
|
||||||
|
|
||||||
|
class WikiPages {
|
||||||
|
constructor(container){
|
||||||
|
this.wikiId = null;
|
||||||
|
}
|
||||||
|
load(wikiId) {
|
||||||
|
console.info('JDG :: Loading wiki', wikiId );
|
||||||
|
this.wikiId = wikiId;
|
||||||
|
}
|
||||||
|
getWikiId() {
|
||||||
|
return this.wikiId;
|
||||||
|
}
|
||||||
|
add(parentPageId, title) {
|
||||||
|
|
||||||
|
}
|
||||||
|
delete() {
|
||||||
|
|
||||||
|
}
|
||||||
|
rename() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class WikiEditor {
|
||||||
|
load(wikiId, wikiPageId) {
|
||||||
|
console.info(`JDG :: Loading Wiki ${wikiId}/${wikiPageId}`);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var MyWiki = MyWiki || {};
|
var MyWiki = MyWiki || {};
|
||||||
|
|
||||||
(function(window, $, exports, undefined) {
|
(function(window, $, exports, undefined) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
$('#MyWiki-test').on('click',test);
|
let wikiNavigation = new WikiNavigation(document.querySelector('li[data-id="wikis"]'), onSelectWiki);
|
||||||
|
let wikiPages = new WikiPages(document.querySelector('li[data-id="pages"]'), onSelectWikiPage);
|
||||||
|
function onSelectWiki(wikiId) {
|
||||||
|
console.info(`JDG :: WikiList selected ${wikiId}` );
|
||||||
|
if ( wikiId > 0 ) {
|
||||||
|
wikiPages.load(wikiId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function onSelectWikiPage(wikiPageId) {
|
||||||
|
console.info(`JDG :: WikiPage selected ${wikiPageId}` );
|
||||||
|
if ( wikiPageId > 0 ) {
|
||||||
|
// wikiEditor.load(wikiPage.getWikiId(), wikiPageId );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------
|
||||||
|
$(`#${appName}-test`).on('click',test);
|
||||||
function test() {
|
function test() {
|
||||||
var baseUrl = OC.generateUrl('/apps/mywiki/wikis');
|
var baseUrl = OC.generateUrl('/apps/mywiki/wikis');
|
||||||
$.ajax({
|
$.ajax({
|
||||||
@ -19,13 +64,8 @@ var MyWiki = MyWiki || {};
|
|||||||
$('output').html('<h2>'+response.statusText+'</h2><code>'+response.responseText+'</code>');
|
$('output').html('<h2>'+response.statusText+'</h2><code>'+response.responseText+'</code>');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// ---------------------------------------------------------------------------------
|
||||||
|
|
||||||
/*
|
|
||||||
// if this function or object should be global, attach it to the namespace
|
|
||||||
exports.myGlobalFunction = function(params) {
|
|
||||||
return params;
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
})(window, jQuery, MyWiki);
|
})(window, jQuery, MyWiki);
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,12 +51,12 @@
|
|||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
*
|
*
|
||||||
|
* @param string $folderPath
|
||||||
* @param string $title
|
* @param string $title
|
||||||
* @param string $fileId
|
*/
|
||||||
*/
|
public function create(string $folderPath, string $title) {
|
||||||
public function create(string $title, int $fileId) {
|
return $this->handleReadOnly(function () use ($folderPath, $title) {
|
||||||
return $this->handleReadOnly(function () use ($title, $fileId) {
|
return $this->service->create($folderPath, $title, $this->userId);
|
||||||
return $this->service->create($title, $fileId, $this->userId);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ class Wiki extends Entity implements JsonSerializable {
|
|||||||
return [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'title' => $this->title,
|
'title' => $this->title,
|
||||||
'file_id' => $this->file_id
|
'fileId' => $this->fileId
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ use OCP\AppFramework\Db\QBMapper;
|
|||||||
class WikiMapper extends QBMapper {
|
class WikiMapper extends QBMapper {
|
||||||
|
|
||||||
public function __construct(IDBConnection $db) {
|
public function __construct(IDBConnection $db) {
|
||||||
parent::__construct($db, 'mywiki_wikis', Note::class);
|
parent::__construct($db, 'mywiki', Wiki::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function usersCount(int $folderId) {
|
public function usersCount(int $folderId) {
|
||||||
@ -24,18 +24,17 @@ class WikiMapper extends QBMapper {
|
|||||||
public function find(int $id, string $userId) {
|
public function find(int $id, string $userId) {
|
||||||
$qb = $this->db->getQueryBuilder();
|
$qb = $this->db->getQueryBuilder();
|
||||||
|
|
||||||
$qb->select('*')
|
$qb->select('*')
|
||||||
->from($this->getTableName())
|
->from($this->getTableName())
|
||||||
->where(
|
->where(
|
||||||
$qb->expr()->eq('id', $qb->createNamedParameter($id))
|
$qb->expr()->eq('id', $qb->createNamedParameter($id))
|
||||||
)->andWhere(
|
)->andWhere(
|
||||||
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId))
|
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId))
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this->findEntity($qb);
|
return $this->findEntity($qb);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function findAll(string $userId) {
|
public function findAll(string $userId, mixed $filter=null) {
|
||||||
$qb = $this->db->getQueryBuilder();
|
$qb = $this->db->getQueryBuilder();
|
||||||
|
|
||||||
$qb->select('*')
|
$qb->select('*')
|
||||||
@ -44,6 +43,18 @@ class WikiMapper extends QBMapper {
|
|||||||
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId))
|
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($filter) {
|
||||||
|
if (array_key_exists('title',$filter) ) {
|
||||||
|
$qb->where(
|
||||||
|
$qb->expr()->eq('title', $qb->createNamedParameter($id))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (array_key_exists('fileId',$filter) ) {
|
||||||
|
$qb->where(
|
||||||
|
$qb->expr()->eq('fileId', $qb->createNamedParameter($id))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
return $this->findEntities($qb);
|
return $this->findEntities($qb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,16 +96,24 @@ class WikiHelper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function initWiki(string $title) :bool {
|
public function initWiki(string $folderPath, string $title) :?int {
|
||||||
$wiki = [
|
$this->wikiFolder = $this->userFolder->get($folderPath);
|
||||||
"title"=>$title,
|
if ( !$this->isWiki() ) {
|
||||||
"folderId"=>$this->wikiFolder->getId(),
|
return null;
|
||||||
"pages"=>$this->rebuildWikiTree()
|
|
||||||
];
|
|
||||||
if ( $this->getWikiData() === null ) {
|
|
||||||
return $this->setWikiData($wiki);
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
$folderId = $this->wikiFolder->getId();
|
||||||
|
if ( $this->getWikiData() === null ) {
|
||||||
|
$wiki = [
|
||||||
|
"title"=>$title,
|
||||||
|
"folderId"=>$folderId,
|
||||||
|
"pages"=>$this->rebuildWikiTree()
|
||||||
|
];
|
||||||
|
if ( !$this->setWikiData($wiki) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $folderId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add(int $parentId, string $title) {
|
public function add(int $parentId, string $title) {
|
||||||
|
83
lib/Helper/WikiTree.php
Normal file
83
lib/Helper/WikiTree.php
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
namespace OCA\MyWiki\Helper;
|
||||||
|
|
||||||
|
class WikiTree {
|
||||||
|
private array $wikiPages;
|
||||||
|
|
||||||
|
public function __construct(?array $wikiPages) {
|
||||||
|
$this->wikiPages = $wikiPages??[];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWikiPages(): array {
|
||||||
|
return $this->wikiPages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get($id): ?WikiTreePage {
|
||||||
|
$wikiTreePage = null;
|
||||||
|
foreach($this->wikiPages as $page) {
|
||||||
|
if ( $page['id']==$id) {
|
||||||
|
$wikiTreePage = new WikiTreePage();
|
||||||
|
$wikiTreePage->id = $page['id'];
|
||||||
|
$wikiTreePage->pid = $page['pid'];
|
||||||
|
$wikiTreePage->title = $page['title'];
|
||||||
|
$wikiTreePage->sort = $page['sort'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $wikiTreePage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function countChilds($id): int {
|
||||||
|
$n = 0;
|
||||||
|
foreach($this->wikiPages as $page) {
|
||||||
|
if ($page['pid']==$id) {
|
||||||
|
$n++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $n;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set(WikiTreePage $wikiTreePage): WikiTree {
|
||||||
|
if ( $this->get($wikiTreePage->id) === null ) {
|
||||||
|
$this->add($wikiTreePage);
|
||||||
|
} else {
|
||||||
|
$this->modify($wikiTreePage);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function add(WikiTreePage $wikiTreePage): WikiTree {
|
||||||
|
if ($wikiTreePage->sort<=0) {
|
||||||
|
$wikiTreePage->sort = $this->countChilds($wikiTreePage->pid) + 1;
|
||||||
|
}
|
||||||
|
$this->wikiPages[] = [
|
||||||
|
"id"=>$wikiTreePage->id,
|
||||||
|
"pid"=>$wikiTreePage->pid,
|
||||||
|
"title"=>$wikiTreePage->title,
|
||||||
|
"sort"=>$wikiTreePage->sort
|
||||||
|
];
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function modify(WikiTreePage $wikiTreePage): WikiTree {
|
||||||
|
foreach($this->wikiPages as &$page) {
|
||||||
|
if ( $page['id']==$wikiTreePage->id) {
|
||||||
|
$page['pid'] = $wikiTreePage->pid;
|
||||||
|
$page['title'] = $wikiTreePage->title;
|
||||||
|
$page['sort'] = $wikiTreePage->sort;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function del($id): ?WikiTree {
|
||||||
|
$pages = [];
|
||||||
|
foreach($this->wikiPages as $k => $page) {
|
||||||
|
if ($page['id']!=$id && $page['pid']!=$id) {
|
||||||
|
$pages[] = $page;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->wikiPages = $pages;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
9
lib/Helper/WikiTreePage.php
Normal file
9
lib/Helper/WikiTreePage.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
namespace OCA\MyWiki\Helper;
|
||||||
|
|
||||||
|
class WikiTreePage {
|
||||||
|
public int $id;
|
||||||
|
public int $pid;
|
||||||
|
public string $title;
|
||||||
|
public int $sort = 0;
|
||||||
|
}
|
@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
$table->setPrimaryKey(['id']);
|
$table->setPrimaryKey(['id']);
|
||||||
$table->addIndex(['user_id'], 'mywiki_user_id_index');
|
$table->addIndex(['user_id'], 'mywiki_user_id_index');
|
||||||
|
$table->addIndex(['file_id'], 'mywiki_file_id_index');
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -25,7 +25,7 @@ class WikiService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function test() {
|
public function test() {
|
||||||
$folderId = 381;
|
$folderId = 880;
|
||||||
return $this->wikiHelper->setFolderId($folderId)->reloadWikiTree();
|
return $this->wikiHelper->setFolderId($folderId)->reloadWikiTree();
|
||||||
return $this->wikiHelper->setFolderId($folderId)->rename(707, 'UnoMasUno');
|
return $this->wikiHelper->setFolderId($folderId)->rename(707, 'UnoMasUno');
|
||||||
return $this->wikiHelper->setFolderId($folderId)->rename(647, 'RenameTest3');
|
return $this->wikiHelper->setFolderId($folderId)->rename(647, 'RenameTest3');
|
||||||
@ -57,17 +57,20 @@ class WikiService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(string $title, int $fileId, string $userId) {
|
public function create(string $folderPath, string $title, string $userId) {
|
||||||
$this->wikiHelper->setFolderId($fileId);
|
$folderId = $this->wikiHelper->initWiki($folderPath, $title);
|
||||||
if ( $this->wikiHelper->isWiki() ) {
|
if ( $folderId === null ) {
|
||||||
if ( !$this->wikiHelper->initWiki($title) ) {
|
throw new ReadOnlyException('Error creating wiki');
|
||||||
throw new ReadOnlyException('Error creating wiki');
|
}
|
||||||
}
|
|
||||||
|
$wikis = $this->mapper->findAll($userId, ['fileId'=>$folderId]);
|
||||||
|
if ( count($wikis)>0 ) {
|
||||||
|
return $wikis[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
$wiki = new Wiki();
|
$wiki = new Wiki();
|
||||||
$wiki->setTitle($title);
|
$wiki->setTitle($title);
|
||||||
$wiki->setFileId($fileId);
|
$wiki->setFileId($folderId);
|
||||||
$wiki->setUserId($userId);
|
$wiki->setUserId($userId);
|
||||||
return $this->mapper->insert($wiki);
|
return $this->mapper->insert($wiki);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
\OCP\Util::addScript('mywiki', 'WikiDropdownHelper');
|
||||||
|
\OCP\Util::addScript('mywiki', 'WikiNavigation');
|
||||||
\OCP\Util::addScript('mywiki', 'script');
|
\OCP\Util::addScript('mywiki', 'script');
|
||||||
\OCP\Util::addStyle('mywiki', 'style');
|
\OCP\Util::addStyle('mywiki', 'style');
|
||||||
?>
|
?>
|
||||||
|
@ -1,10 +1,51 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<li><a href="#">First level entry</a></li>
|
<li data-id="wikis">
|
||||||
<li>
|
<select></select>
|
||||||
<a href="#">First level container</a>
|
<div class="app-navigation-entry-utils">
|
||||||
|
<ul>
|
||||||
|
<li class="app-navigation-entry-utils-menu-button">
|
||||||
|
<button></button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="app-navigation-entry-menu">
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#">Second level entry</a></li>
|
<li>
|
||||||
<li><a href="#">Second level entry</a></li>
|
<a href="#" data-id="add">
|
||||||
|
<span class="icon-add"></span>
|
||||||
|
<span>Add</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="#" data-id="rename">
|
||||||
|
<span class="icon-rename"></span>
|
||||||
|
<span>Edit</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="#" data-id="delete">
|
||||||
|
<span class="icon-delete"></span>
|
||||||
|
<span>Remove</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
|
||||||
|
<li data-id="pages">
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div id="myWikiTree">
|
||||||
|
no data
|
||||||
|
</div>
|
@ -6,5 +6,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="app-settings-content">
|
<div id="app-settings-content">
|
||||||
<!-- Your settings in here -->
|
<!-- Your settings in here -->
|
||||||
|
<ul class="with-icon">
|
||||||
|
<li data-id="deleteWiki">
|
||||||
|
<a href="#" class="icon-delete svg">Delete Current Wiki</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
50
tests/Unit/Helper/WikiTreeHelperTest.php
Normal file
50
tests/Unit/Helper/WikiTreeHelperTest.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
// sudo ./vendor/phpunit/phpunit/phpunit tests/Unit/Helper/WikiTreeHelperTest.php
|
||||||
|
|
||||||
|
namespace OCA\MyWiki\Tests\Unit\Helper;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use OCA\MyWiki\Helper\WikiTree;
|
||||||
|
use OCA\MyWiki\Helper\WikiTreePage;
|
||||||
|
|
||||||
|
class WikiTreeHelperTest extends TestCase {
|
||||||
|
public function testGetSetDel() {
|
||||||
|
$wikiTree = new WikiTree(null);
|
||||||
|
|
||||||
|
$wikiPage = new WikiTreePage();
|
||||||
|
$wikiPage->id = 1;
|
||||||
|
$wikiPage->pid = 0;
|
||||||
|
$wikiPage->title = 'Page1';
|
||||||
|
$wikiPage->sort = 0;
|
||||||
|
$wikiTree->set($wikiPage);
|
||||||
|
|
||||||
|
$wikiPage->id = 2;
|
||||||
|
$wikiPage->pid = 0;
|
||||||
|
$wikiPage->title = 'Page3';
|
||||||
|
$wikiPage->sort = 0;
|
||||||
|
$wikiTree->set($wikiPage);
|
||||||
|
|
||||||
|
$wikiPage->title = 'Page2';
|
||||||
|
$wikiTree->set($wikiPage);
|
||||||
|
|
||||||
|
$wikiPage->id = 11;
|
||||||
|
$wikiPage->pid = 1;
|
||||||
|
$wikiPage->title = 'Page1.1';
|
||||||
|
$wikiPage->sort = 0;
|
||||||
|
$wikiTree->set($wikiPage);
|
||||||
|
|
||||||
|
$pages = $wikiTree->getWikiPages();
|
||||||
|
$this->assertEquals(3, count($pages));
|
||||||
|
$this->assertEquals('Page2', $pages[1]['title']);
|
||||||
|
|
||||||
|
$wikiTree->del(1);
|
||||||
|
$pages = $wikiTree->getWikiPages();
|
||||||
|
$this->assertEquals(1, count($pages));
|
||||||
|
|
||||||
|
$page = $wikiTree->get(2);
|
||||||
|
$this->assertEquals(2, $page->id);
|
||||||
|
$this->assertEquals(0, $page->pid);
|
||||||
|
$this->assertEquals('Page2', $page->title);
|
||||||
|
$this->assertEquals(2, $page->sort);
|
||||||
|
}
|
||||||
|
}
|
4
vendor/composer/installed.php
vendored
4
vendor/composer/installed.php
vendored
@ -5,7 +5,7 @@
|
|||||||
'type' => 'project',
|
'type' => 'project',
|
||||||
'install_path' => __DIR__ . '/../../',
|
'install_path' => __DIR__ . '/../../',
|
||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'reference' => 'a30a4f13ec699c6e80f32148dc3aa017511c5f5a',
|
'reference' => '9c6114cf8643a84a9536074942d2e7f1a8451cd0',
|
||||||
'name' => 'jdg/mywiki',
|
'name' => 'jdg/mywiki',
|
||||||
'dev' => true,
|
'dev' => true,
|
||||||
),
|
),
|
||||||
@ -25,7 +25,7 @@
|
|||||||
'type' => 'project',
|
'type' => 'project',
|
||||||
'install_path' => __DIR__ . '/../../',
|
'install_path' => __DIR__ . '/../../',
|
||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
'reference' => 'a30a4f13ec699c6e80f32148dc3aa017511c5f5a',
|
'reference' => '9c6114cf8643a84a9536074942d2e7f1a8451cd0',
|
||||||
'dev_requirement' => false,
|
'dev_requirement' => false,
|
||||||
),
|
),
|
||||||
'myclabs/deep-copy' => array(
|
'myclabs/deep-copy' => array(
|
||||||
|
Reference in New Issue
Block a user