Testing how to develop an app

This commit is contained in:
root 2022-03-14 20:05:46 +00:00
parent 1984e55837
commit a30a4f13ec
11 changed files with 99 additions and 38 deletions

View File

@ -74,3 +74,5 @@ https://c.infdj.com/apps/files/?dir=/Documents/Manuals%20-%20Drivers/drivers/MAD
https://docs.nextcloud.com/server/latest/developer_manual/digging_deeper/api.html https://docs.nextcloud.com/server/latest/developer_manual/digging_deeper/api.html
phpunit -c phpunit.integration.xml phpunit -c phpunit.integration.xml
https://github.com/nextcloud/nextcloud-vue

View File

@ -9,9 +9,11 @@
*/ */
return [ return [
'resources' => [ 'resources' => [
'wiki' => ['url' => '/wiki'] 'wiki' => ['url' => '/wikis']
], ],
'routes' => [ 'routes' => [
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'] ['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
['name' => 'page#test', 'url' => '/test', 'verb' => 'GET'],
['name' => 'wiki#test', 'url' => '/wikis/test', 'verb' => 'GET']
] ]
]; ];

View File

@ -0,0 +1,34 @@
var MyWiki = MyWiki || {};
(function(window, $, exports, undefined) {
'use strict';
$('#MyWiki-test').on('click',test);
function test() {
var baseUrl = OC.generateUrl('/apps/mywiki/wikis');
$.ajax({
url: baseUrl + '/test',
type: 'GET',
contentType: 'application/json'
}).done(function (response) {
// handle success
$('output').html(response);
}).fail(function (response, code) {
// handle failure
$('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);

View File

@ -28,4 +28,11 @@ class PageController extends Controller {
return new TemplateResponse('mywiki', 'index'); // templates/index.php return new TemplateResponse('mywiki', 'index'); // templates/index.php
} }
/**
* @NoAdminRequired
*/
public function test() {
return new DataResponse('JDG::Test');
}
} }

View File

@ -23,9 +23,15 @@
/** /**
* @NoAdminRequired * @NoAdminRequired
*/ */
public function index() { public function test() {
return new DataResponse($this->service->test($this->userId)); $x = $this->service->test($this->userId);
return new DataResponse(print_r($x,true));
}
/**
* @NoAdminRequired
*/
public function index() {
return new DataResponse($this->service->findAll($this->userId)); return new DataResponse($this->service->findAll($this->userId));
} }

View File

@ -1,32 +1,25 @@
<?php <?php
namespace OCA\MyWiki\Helper; namespace OCA\MyWiki\Helper;
use OCP\AppFramework\Files\Folder; use OCP\Files\IRootFolder;
class WikiHelper { class WikiHelper {
public static function isFolder(int $folderId) :bool { public static function isFolder(IRootFolder $storage, int $folderId) :bool {
$mount = \OC\Files\Filesystem::getMountsForFileId($folderId); $nodes = $storage->getById($folderId);
/* if ( count($nodes)>0 ) {
isReadable() return $nodes[0]->getType() == \OCP\Files\Node::TYPE_FOLDER;
getById($folderId) }
isCreatable() return false;
isUpdateable()
lock()
$config = new \OC\Config('config/');
$base_path = $config->getValue('datadirectory')
datadirectory is the key in the array defined in config.php that contains the base directory.
$basepath now contains a path like /var/www/html/nextcloud/data.
*/
// ToDo
$nodes = \OC\Files\Node\Folder::getById($folderId);
return true;
} }
public static function isWiki(int $folderId) :bool { public static function isWiki(IRootFolder $storage, int $folderId) :string {
return \OC\Files\Filesystem::nodeExists('.wiki'); $nodes = $storage->getById($folderId);
if ( count($nodes)>0 ) {
$nodeStorage = $nodes[0]->getStorage();
return $nodeStorage->file_get_contents('/wiki.yaml');
// getPath()
// getStorage()
}
return false;
} }
public static function initWiki(int $folderId, string $title) :bool { public static function initWiki(int $folderId, string $title) :bool {
// ToDo // ToDo

View File

@ -1,13 +1,13 @@
<?php <?php
namespace OCA\NotesTutorial\Migration; namespace OCA\MyWiki\Migration;
use Closure; use Closure;
use OCP\DB\ISchemaWrapper; use OCP\DB\ISchemaWrapper;
use OCP\Migration\SimpleMigrationStep; use OCP\Migration\SimpleMigrationStep;
use OCP\Migration\IOutput; use OCP\Migration\IOutput;
class Version1400Date20181013124731 extends SimpleMigrationStep { class Version000000Date20220302210900 extends SimpleMigrationStep {
/** /**
* @param IOutput $output * @param IOutput $output

View File

@ -10,20 +10,28 @@ use OCA\MyWiki\Db\Wiki;
use OCA\MyWiki\Db\WikiMapper; use OCA\MyWiki\Db\WikiMapper;
use OCA\MyWiki\Helper\WikiHelper; use OCA\MyWiki\Helper\WikiHelper;
use \OCP\Files\Storage;
use \OCP\Files\IRootFolder;
use \OCP\IUserSession;
class WikiService { class WikiService {
private $mapper; private $mapper;
private $rootFolder; private $storage;
private $userSession;
public function __construct(WikiMapper $mapper,IRootFolder $rootFolder){ public function __construct(WikiMapper $mapper, IRootFolder $storage) {
// , IUserSession $userSession ) {
$this->mapper = $mapper; $this->mapper = $mapper;
$this->rootFolder = $rootFolder; // $this->userSession = $userSession;
$this->storage = $storage;
// , IUserSession $userSession // , IUserSession $userSession
} }
public function test(string $userId) { public function test(string $userId) {
echo 'JDG :: Test for '.$userId; return WikiHelper::isWiki($this->storage, 208);
} }
public function findAll(string $userId) { public function findAll(string $userId) {

View File

@ -1 +1,10 @@
<h1>Hello world</h1> <h1>Hello world</h1>
<div id="emptycontent">
<div>
<button id="MyWiki-test">Test</button>
</div>
<div>
<output></output>
</div>
</div>

View File

@ -1,6 +1,6 @@
<?php <?php
script('mywiki', 'script'); \OCP\Util::addScript('mywiki', 'script');
style('mywiki', 'style'); \OCP\Util::addStyle('mywiki', 'style');
?> ?>
<div id="app"> <div id="app">

View File

@ -5,7 +5,7 @@
'type' => 'project', 'type' => 'project',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
'reference' => '9254fe2d3d9dba572f9f5e831eda5f0896e82e3e', 'reference' => '1984e55837df92230d61b2bce1fcf2e08e2ec4a9',
'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' => '9254fe2d3d9dba572f9f5e831eda5f0896e82e3e', 'reference' => '1984e55837df92230d61b2bce1fcf2e08e2ec4a9',
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'myclabs/deep-copy' => array( 'myclabs/deep-copy' => array(