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

RO session handling

parent 07dfbbc9
This diff is collapsed.
This diff is collapsed.
......@@ -107,7 +107,7 @@ class CollaborationEngine {
public function addStep(string $type, string $datas) {
$this->updateLastSeen($this->userId,$this->ressourceId) ;
if ($this->setUserWriteAccess) {
if ($this->userWriteAccess) {
$Nstep = new Step() ;
$Nstep->setAppId($this->AppName) ;
......@@ -120,7 +120,8 @@ class CollaborationEngine {
return $this->StepMapper->insert($Nstep);
} else {
throw new ForbiddenException ;
throw new ForbiddenException("RO Session",FALSE) ;
//BUG !!
}
}
......
......@@ -33,7 +33,7 @@
menu-position="right" />
</li>
</ul>
<div v-if="ROSession" class="ro">
<div v-if="ROSession == true" class="ro">
You don't have write access to this ressource, your modifications won't be forwarded and won't be saved
</div>
<AppContent :id="appEditor">
......@@ -68,10 +68,16 @@ export default {
data: function() {
return {
userList: this.$parent.userList,
ROSession: this.$parent.ROSession,
// sessionInfoRO: this.$parent.sessionInfo.ROSession,
}
},
computed: {
ROSession: function() {
return this.$parent.sessionInfo.ROSession
},
},
destroyed: function() {
document.getElementById('app-content-' + this.appName).remove()
document.body.style.overflowY = ''
......
......@@ -30,7 +30,7 @@ export default {
name: 'collaborationEngine',
start: function(appName, filename, context) {
start: async function(appName, filename, context) {
const self = this
......@@ -38,37 +38,37 @@ export default {
this.filename = filename
this.context = context
this.init().then(function(sessionInfo) {
const sessData = await this.init()
self.sessionInfo = sessionInfo.data
this.sessionInfo = sessData.data
console.debug('sessionInfo', sessionInfo.data)
console.debug('sessionInfo', this.sessionInfo)
self.addUser()
.then(function(userType) {
console.debug('User :', userType.data)
})
// because we may arrive in an allready running session
// get all steps from last save
self.getAllSteps()
.then(function(steps) {
steps.data.forEach(step => emit(self.appName + '::externalAddStep', step))
}).catch(function(error) {
console.debug(error.reponse)
})
this.addUser()
.then(function(userType) {
console.debug('User :', userType.data)
})
// get users connected to the file
self.getUserList().then(function(users) {
emit(self.appName + '::usersListChanged', users)
// because we may arrive in an allready running session
// get all steps from last save
this.getAllSteps()
.then(function(steps) {
steps.data.forEach(step => emit(self.appName + '::externalAddStep', step))
}).catch(function(error) {
console.debug(error.reponse)
})
// start pulling for change
self.communicationStarted = true
// console.log('CE : starting communication ')
self.startCommunication()
// get users connected to the file
self.getUserList().then(function(users) {
emit(self.appName + '::usersListChanged', users)
})
// start pulling for change
self.communicationStarted = true
// console.log('CE : starting communication ')
self.startCommunication()
return this.sessionInfo
},
stop: function() {
......@@ -80,11 +80,9 @@ export default {
const url = generateUrl('apps/' + this.appName + '/collaboration/startsession')
this.id = window.FileList.findFile(this.filename).id
const ajx = axios.post(url, {
return axios.post(url, {
id: this.id,
})
return ajx
},
addUser: function() {
......@@ -98,52 +96,59 @@ export default {
},
removeUser: function() {
const url = generateUrl('apps/' + this.appName + '/collaboration/removeuser')
// console.log('CE : Removing user ' + OC.currentUser)
const ajx = axios.post(url, {
return axios.post(url, {
id: this.id,
})
return ajx
},
sendStep: function(payload) {
const self = this
const url = generateUrl('apps/' + this.appName + '/collaboration/addstep')
// console.log('CE : Sending ', payload.type, ' step')
return axios.post(url, {
id: this.id,
type: payload.type,
step: JSON.stringify(payload.step),
}).catch((error) => {
console.error('Network or server error, waiting 5 sec before retry -> ', error.message)
setTimeout(() => { self.sendStep(payload) }, 5000)
return Promise.reject(error)
})
if (!this.sessionInfo.ROSession) {
const self = this
const url = generateUrl('apps/' + this.appName + '/collaboration/addstep')
return axios.post(url, {
id: this.id,
type: payload.type,
step: JSON.stringify(payload.step),
}).catch((error) => {
if (error.response.status === 403) {
console.debug('RO Session, updating is not permitted')
return true
} else {
if (self.communicationStarted === true) {
console.error('Network or server error, waiting 5 sec before retry -> ', error.reponse.status)
setTimeout(() => { self.sendStep(payload) }, 5000)
return true
}
}
})
}
},
getAllSteps: function() {
const url = generateUrl('apps/' + this.appName + '/collaboration/getallsteps')
const ajx = axios.get(url, {
return axios.get(url, {
params: {
id: this.id,
},
})
return ajx
},
getUserList: function() {
const url = generateUrl('apps/' + this.appName + '/collaboration/getuserlist')
const ajx = axios.get(url, {
return axios.get(url, {
params: {
id: this.id,
},
})
return ajx
},
startCommunication: function() {
......
......@@ -45,7 +45,7 @@ export default {
this.NewFileMenu.APP_MIME = APP_MIME
this.userList = []
this.sessionInfo = []
this.sessionInfo = {}
OC.Plugins.register('OCA.Files.NewFileMenu', this.NewFileMenu)
this.registerFileActions()
......@@ -74,7 +74,7 @@ export default {
this.vm = new Vue({
data: {
userList: this.userList,
ROSession: this.sessionInfo.ROSession,
sessionInfo: {},
},
render: h => h(
PrototypeView,
......@@ -153,22 +153,20 @@ export default {
},
// start editing
startEdit: function(filename, context) {
startEdit: async function(filename, context) {
const self = this
this.loadContent().then(function(content) {
// start the editor
self.ED = editor
self.ED.start(self.APP_NAME, content)
})
// get the content and start the editor
const content = await this.loadContent()
this.ED = editor
this.ED.start(self.APP_NAME, content)
// start the collaboration Engine
this.CE = collaborationEngine
this.CE.start(this.APP_NAME, filename, context)
this.sessionInfo = this.CE.sessionInfo
this.sessionInfo = await this.CE.start(this.APP_NAME, filename, context)
this.vm.sessionInfo = this.sessionInfo
// subscribtion to event bus
// local changes => send to Engine
subscribe(this.APP_NAME + '::editorAddStep', this.EDS = (data) => {
......@@ -186,6 +184,8 @@ export default {
users.data.forEach(user => this.userList.push(user))
})
return true
},
// stop editing
......@@ -226,23 +226,22 @@ export default {
// save edit
saveEdit: function() {
if (!this.sessionInfo.ROSession) {
const content = this.ED.getSave()
const self = this
const url = generateUrl('apps/' + this.APP_NAME + '/file/save')
const content = this.ED.getSave()
const self = this
const url = generateUrl('apps/' + this.APP_NAME + '/file/save')
axios.post(url, {
content: JSON.stringify(content),
path: this.context.dir + '/' + this.filename,
}).then(function() {
OC.Notification.showTemporary('File saved')
const payload = {
'type': 'save',
'step': 'NA',
}
emit(self.APP_NAME + '::editorAddStep', payload)
})
axios.post(url, {
content: JSON.stringify(content),
path: this.context.dir + '/' + this.filename,
}).then(function() {
OC.Notification.showTemporary('File saved')
const payload = {
'type': 'save',
'step': 'NA',
}
emit(self.APP_NAME + '::editorAddStep', payload)
})
}
},
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment