Commit de581e24 authored by Matthieu Le Corre's avatar Matthieu Le Corre

make app a lot's more reusable

Signed-off-by: Matthieu Le Corre's avatarMatthieu Le Corre <matthieu.lecorre@univ-nantes.fr>
parent a52a5789
......@@ -22,7 +22,14 @@
return [
'routes' => [
[ 'name' => 'file#save', 'url' => '/file/save', 'verb' => 'POST' ],
[ 'name' => 'file#load', 'url' => '/file/load', 'verb' => 'GET' ]
[ 'name' => 'file#load', 'url' => '/file/load', 'verb' => 'GET' ],
[ 'name'=> 'collaboration#createSession', 'url' => '/collaboration/createsession','verb' => 'POST'],
[ 'name'=> 'collaboration#addStep', 'url' => '/collaboration/addstep','verb' => 'POST'],
[ 'name'=> 'collaboration#getStep', 'url' => '/collaboration/getstep','verb' => 'GET'],
[ 'name'=> 'collaboration#addUser', 'url' => '/collaboration/adduser','verb' => 'POST'],
[ 'name'=> 'collaboration#removeUser', 'url' => '/collaboration/removeuser','verb' => 'POST']
]
];
......@@ -10,25 +10,42 @@
overflow: hidden;
}
#closebtn {
.icon-whiteboard {
background-image: url("../img/whiteboard.svg");
}
/*button*/
#whiteboard-savebtn {
position: absolute;
top:0 ;
right: 0 ;
right: 30px ;
width: 30px ;
height: 30Px ;
z-index: inherit;
background-color: lawngreen;
}
#closebtn:hover {
#whiteboard-savebtn:hover {
border: 1px solid silver ;
border-radius: 2px ;
}
#whiteboard-closebtn {
position: absolute;
top:0 ;
right: 0 ;
width: 30px ;
height: 30Px ;
z-index: inherit;
}
.icon-whiteboard {
background-image: url("../img/whiteboard.svg");
#whiteboard-closebtn:hover {
border: 1px solid silver ;
border-radius: 2px ;
}
/*Editor stuff*/
.literally {
background-color: white !important;
position: initial !important ;
......
(window["webpackJsonpFileWhiteboard"] = window["webpackJsonpFileWhiteboard"] || []).push([[2],{
/***/ 75:
/***/ (function(module, exports) {
throw new Error("Module build failed: Error: ENOENT: no such file or directory, open '/var/www/html/stable18/apps/whiteboard/src/appconfig.js'");
/***/ })
}]);
//# sourceMappingURL=2.js.map
\ No newline at end of file
{"version":3,"sources":[],"names":[],"mappings":"","file":"2.js","sourceRoot":""}
\ No newline at end of file
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 1);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */,
/* 1 */
/***/ (function(module, exports) {
/**
* @author Matthieu Le Corre <matthieu.lecorre@univ-nantes.fr>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* @namespace collaboration
*/
collaborationEngine = {
startSession: function(filename) {
var url = OC.generateUrl('apps/whiteboard/collaboration/createsession');
var id = window.FileList.findFile(filename).id
console.log("Create session for id #"+id) ;
ajx = $.ajax({
type: 'POST',
url: url,
data: {id: id }
}) ;
return ajx.promise() ;
},
addUser: function(filename) {
var url = OC.generateUrl('apps/whiteboard/collaboration/adduser');
var id = window.FileList.findFile(filename).id
console.log("Adding user " + OC.currentUser ) ;
ajx = $.ajax({
type: 'POST',
url: url,
data: {id: id,
user: OC.currentUser
}
}) ;
return ajx.promise() ;
}
}
/***/ })
/******/ ]);
//# sourceMappingURL=collaboration.js.map
\ No newline at end of file
{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///./src/collaboration.js"],"names":[],"mappings":";QAAA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA,0CAA0C,gCAAgC;QAC1E;QACA;;QAEA;QACA;QACA;QACA,wDAAwD,kBAAkB;QAC1E;QACA,iDAAiD,cAAc;QAC/D;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA,yCAAyC,iCAAiC;QAC1E,gHAAgH,mBAAmB,EAAE;QACrI;QACA;;QAEA;QACA;QACA;QACA,2BAA2B,0BAA0B,EAAE;QACvD,iCAAiC,eAAe;QAChD;QACA;QACA;;QAEA;QACA,sDAAsD,+DAA+D;;QAErH;QACA;;;QAGA;QACA;;;;;;;;AClFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;;AAGA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,mBAAmB;AACnB,SAAS;;AAET;AACA,KAAK;;AAEL;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,mBAAmB;AACnB;AACA;AACA,SAAS;;AAET;;AAEA;;;;AAIA","file":"collaboration.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 1);\n","/**\n * @author Matthieu Le Corre <matthieu.lecorre@univ-nantes.fr>\n *\n * @license GNU AGPL version 3 or any later version\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the\n * License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU Affero General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\n \n/**\n* @namespace collaboration\n*/\ncollaborationEngine = {\n\n startSession: function(filename) {\n var url = OC.generateUrl('apps/whiteboard/collaboration/createsession');\n var id = window.FileList.findFile(filename).id\n console.log(\"Create session for id #\"+id) ;\n ajx = $.ajax({\n type: 'POST',\n url: url,\n data: {id: id }\n }) ;\n \n return ajx.promise() ;\n },\n\n addUser: function(filename) {\n var url = OC.generateUrl('apps/whiteboard/collaboration/adduser');\n var id = window.FileList.findFile(filename).id\n console.log(\"Adding user \" + OC.currentUser ) ;\n\n ajx = $.ajax({\n type: 'POST',\n url: url,\n data: {id: id,\n user: OC.currentUser\n }\n }) ;\n \n return ajx.promise() ;\n \n }\n\n\n\n}\n\n"],"sourceRoot":""}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?php
/**
* @author 2020 Matthieu Le Corre <matthieu.lecorre@univ-nantes.fr>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\whiteboard\Collaboration ;
use OCP\User ;
interface ICollaborationEngine {
public function createSession(string $fileId): int ;
public function addUser(User $user): int ;
public function removeUser(User $user): int ;
public function addStep(string $step): int ;
public function getStep(): array ;
}
\ No newline at end of file
<?php
/**
* @author 2020 Matthieu Le Corre <matthieu.lecorre@univ-nantes.fr>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\whiteboard\Collaboration ;
//use OCP\User ;
//class SimpleFileCollaborationEngine implements ICollaborationEngine {
class SimpleFileCollaborationEngine {
public function __construct(string $fileId) {
$this->file = $fileId ;
$this->Fsession =Array() ;
$this->Fsession = json_decode(file_get_contents("/tmp/session-".$this->file),true) ;
}
public function createSession(string $file) {
$this->Fsession["session"] = $file ;
return $this-> updateStorage() ;
}
public function addUSer(string $user) {
$this->Fsession["user"][]=$user ;
return $this-> updateStorage() ;
}
public function addStep($datas) {
$step = array (
"data" => $datas,
"stepid" => "1"
) ;
$this->Fsession["steps"][]=$step ;
return $this-> updateStorage() ;
}
public function getStep() {
return $this->Fsession["steps"] ;
}
private function updateStorage() {
return file_put_contents("/tmp/session-".$this->file,json_encode($this->Fsession)) ;
}
}
\ No newline at end of file
<?php
/**
* @author 2020 Matthieu Le Corre <matthieu.lecorre@univ-nantes.fr>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\whiteboard\Controller ;
use OCP\AppFramework\Controller ;
use OCP\IRequest;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\User ;
use OCA\whiteboard\Collaboration\SimpleFileCollaborationEngine ;
class CollaborationController extends Controller {
public function __construct($AppName, IRequest $request, Folder $userFolder ) {
parent::__construct($AppName, $request);
$this->id = $request->getParam("id") ;
$this->engine = new SimpleFileCollaborationEngine($this->id) ;
}
public function createSession($id) {
return $this->engine->createSession($id) ;
}
public function addUser($id,$user) {
return $this->engine->addUser($user) ;
}
}
\ No newline at end of file
......@@ -53,7 +53,7 @@ class FileController extends Controller {
/** @var File $file */
$file = $this->userFolder->get($path);
return $file->getContent($content);
return $file->getContent();
}
}
/**
* @author Matthieu Le Corre <matthieu.lecorre@univ-nantes.fr>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* @namespace collaborationEngine
*/
collaborationEngine = {
startSession: function(filename) {
var url = OC.generateUrl('apps/whiteboard/collaboration/createsession');
var id = window.FileList.findFile(filename).id
console.log("Create session for id #"+id) ;
ajx = $.ajax({
type: 'POST',
url: url,
data: {id: id }
}) ;
return ajx.promise() ;
},
addUser: function(filename) {
var url = OC.generateUrl('apps/whiteboard/collaboration/adduser');
var id = window.FileList.findFile(filename).id
console.log("Adding user " + OC.currentUser ) ;
ajx = $.ajax({
type: 'POST',
url: url,
data: {id: id,
user: OC.currentUser
}
}) ;
return ajx.promise() ;
}
}
/**
* @author Matthieu Le Corre <matthieu.lecorre@univ-nantes.fr>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
export default {
name: "editor",
start: function (app_name,filename,context) {
var self = this ;
this.app_name = app_name ;
this.filename = filename ;
this.context = context ;
this.init().then(function(){
self.loadContent() ;
self.setupCallback() ;
}) ;
},
init: function () {
return import(/* webpackChunkName: "literallycanvas" */ "literallycanvas").then(LC => {
this.whiteboard = LC.init(
document.getElementById(this.app_name+'-editor'),
{
imageURLPrefix: '/stable18/apps/'+this.app_name+'/img/lc_assets' ,
toolbarPosition: 'top'
}
)
}) ;
},
//load whiteboard
loadContent: function() {
var self = this ;
var url = OC.generateUrl('apps/'+this.app_name+'/file/load');
$.ajax({
type: 'GET',
url: url,
data: {path: this.context.dir + "/" + this.filename }
}).done(function(content){
console.log("Loading WB ...") ;
self.whiteboard.loadSnapshot(JSON.parse(content)) ;
}) ;
},
//save whiteboard
saveContent: function() {
var url = OC.generateUrl('apps/'+this.app_name+'/file/save');
var postObject = {
content: JSON.stringify(this.whiteboard.getSnapshot()),
path: this.context.dir + "/" + this.filename
};
$.ajax({
type: 'POST',
url: url,
data: postObject
}).done(function(content){
console.log("Save whiteboard ...") ;
})
},
//setup callback
setupCallback: function (){
var self = this ;
// set save callback
this.whiteboard.on('drawingChange', function() {
self.saveContent() ;
});
},
//destroy editor
close: function() {
this.whiteboard.teardown() ;
}
}
/*if (CONF_MASTER == true) {
$('#closebtn').addClass("master") ;
} else {
setInterval(() => {
//load whiteboard
var url = OC.generateUrl('apps/whiteboard/file/load');
$.ajax({
type: 'GET',
url: url,
data: {path: context.dir + "/" + filename }
}).done(function(content){
console.log("update WB ...") ;
WB.loadSnapshot(JSON.parse(content)) ;
})
}, 300);
}*/
/*require("./collaboration.js") ;
collaborationEngine.startSession(filename)
.done(function(){
console.log("session started")
collaborationEngine.addUser(filename) ;
}) ;
*/
\ No newline at end of file
......@@ -18,159 +18,21 @@
*
*/
/**
* @namespace whiteboard
*/
whiteboardApp = {
// App init
initialise: function() {
var contenair = "<div id=whiteboard-container></div>" ;
this.registerFileActions() ;
},
setupContainer: function() {
$('#content')
.add(this.contenair)
.addClass("viewer-mode")
.addClass("no-sidebar") ;
},
// register file handler
registerFileActions: function() {
var self = this ;
OCA.Files.fileActions.registerAction({
name: 'Edit',
mime: "application/wbr",
permissions: OC.PERMISSION_READ,
icon: function () {
return OC.imagePath('core', 'actions/edit');
},
actionHandler: self.editAction
}) ;
OCA.Files.fileActions.setDefault("application/wbr", 'Edit');
},
//edit