@zklogic/draw.io
Version:
Draw.IO - Graph Editor integration in Angular-cli
1 lines • 7.97 kB
JavaScript
DriveFile=function(i,t,e){DrawioFile.call(this,i,t),this.desc=e},mxUtils.extend(DriveFile,DrawioFile),DriveFile.prototype.saveDelay=0,DriveFile.prototype.allChangesSavedKey="allChangesSavedInDrive",DriveFile.prototype.getSize=function(){return this.desc.fileSize},DriveFile.prototype.isRestricted=function(){return null!=this.desc.userPermission&&null!=this.desc.labels&&"reader"==this.desc.userPermission.role&&this.desc.labels.restricted},DriveFile.prototype.isConflict=function(i){return null!=i&&null!=i.error&&412==i.error.code},DriveFile.prototype.getCurrentUser=function(){return null!=this.ui.drive?this.ui.drive.user:null},DriveFile.prototype.getMode=function(){return App.MODE_GOOGLE},DriveFile.prototype.getPublicUrl=function(i){this.ui.drive.executeRequest({url:"/files/"+this.desc.id+"/permissions?supportsAllDrives=true"},mxUtils.bind(this,(function(t){if(null!=t&&null!=t.items)for(var e=0;e<t.items.length;e++)if("anyoneWithLink"===t.items[e].id||"anyone"===t.items[e].id)return void i(this.desc.webContentLink);i(null)})),mxUtils.bind(this,(function(){i(null)})))},DriveFile.prototype.isAutosaveOptional=function(){return!0},DriveFile.prototype.isRenamable=function(){return this.isEditable()&&DrawioFile.prototype.isEditable.apply(this,arguments)},DriveFile.prototype.isMovable=function(){return this.isEditable()},DriveFile.prototype.isTrashed=function(){return this.desc.labels.trashed},DriveFile.prototype.save=function(i,t,e,s,n){DrawioFile.prototype.save.apply(this,[i,mxUtils.bind(this,(function(){this.saveFile(null,i,t,e,s,n)})),e,s,n])},DriveFile.prototype.saveFile=function(i,t,e,s,n,r){try{this.isEditable()?this.savingFile||(this.savingFileTime=new Date,this.setShadowModified(!1),this.savingFile=!0,this.createSecret(mxUtils.bind(this,(function(i,o){var l=mxUtils.bind(this,(function(r,u){try{var h=this.desc;this.ui.drive.saveFile(this,u,mxUtils.bind(this,(function(i,n){try{this.savingFile=!1,0!=i?(this.setModified(this.getShadowModified()),t&&(this.lastAutosaveRevision=(new Date).getTime()),this.autosaveDelay=Math.round(Math.min(1e4,Math.max(DriveFile.prototype.autosaveDelay,this.saveDelay))),this.desc=i,null!=o?this.fileSaved(n,h,mxUtils.bind(this,(function(){this.contentChanged(),null!=e&&e(i)})),s,o):null!=e&&e(i)):null!=s&&s(i)}catch(i){if(this.savingFile=!1,null==s)throw i;s(i)}})),mxUtils.bind(this,(function(i,t){try{this.savingFile=!1,this.isConflict(i)?(this.inConflictState=!0,null!=this.sync?(this.savingFile=!0,this.sync.fileConflict(t,mxUtils.bind(this,(function(){window.setTimeout(mxUtils.bind(this,(function(){this.updateFileData(),this.setShadowModified(!1),l(r,!0)})),100+500*Math.random())})),mxUtils.bind(this,(function(){this.savingFile=!1,null!=s&&s()})))):null!=s&&s()):null!=s&&s(i)}catch(i){if(this.savingFile=!1,null==s)throw i;s(i)}})),n,n,r,null,i)}catch(i){if(this.savingFile=!1,null==s)throw i;s(i)}}));l(r,t)})))):null!=e&&e()}catch(i){if(null==s)throw i;s(i)}},DriveFile.prototype.copyFile=function(i,t){this.isRestricted()?DrawioFile.prototype.copyFile.apply(this,arguments):this.makeCopy(mxUtils.bind(this,(function(){if(this.ui.spinner.spin(document.body,mxResources.get("saving")))try{this.save(!0,i,t)}catch(i){t(i)}})),t,!0)},DriveFile.prototype.makeCopy=function(i,t,e){this.ui.spinner.spin(document.body,mxResources.get("saving"))&&this.saveAs(this.ui.getCopyFilename(this,e),mxUtils.bind(this,(function(t){this.desc=t,this.ui.spinner.stop(),this.setModified(!1),this.backupPatch=null,this.invalidChecksum=!1,this.inConflictState=!1,this.descriptorChanged(),i()})),mxUtils.bind(this,(function(){this.ui.spinner.stop(),null!=t&&t()})))},DriveFile.prototype.saveAs=function(i,t,e){this.ui.drive.copyFile(this.getId(),i,t,e)},DriveFile.prototype.rename=function(i,t,e){var s=this.getCurrentEtag();this.ui.drive.renameFile(this.getId(),i,mxUtils.bind(this,(function(n){this.hasSameExtension(i,this.getTitle())?(this.desc=n,this.descriptorChanged(),null!=this.sync&&this.sync.descriptorChanged(s),null!=t&&t(n)):(this.desc=n,null!=this.sync&&this.sync.descriptorChanged(s),this.save(!0,t,e))})),e)},DriveFile.prototype.move=function(i,t,e){this.ui.drive.moveFile(this.getId(),i,mxUtils.bind(this,(function(i){this.desc=i,this.descriptorChanged(),null!=t&&t(i)})),e)},DriveFile.prototype.share=function(){this.ui.drive.showPermissions(this.getId())},DriveFile.prototype.getTitle=function(){return this.desc.title},DriveFile.prototype.getHash=function(){return"G"+this.getId()},DriveFile.prototype.getId=function(){return this.desc.id},DriveFile.prototype.isEditable=function(){return DrawioFile.prototype.isEditable.apply(this,arguments)&&this.desc.editable},DriveFile.prototype.isSyncSupported=function(){return!0},DriveFile.prototype.isRevisionHistorySupported=function(){return!0},DriveFile.prototype.getRevisions=function(i,t){this.ui.drive.executeRequest({url:"/files/"+this.getId()+"/revisions"},mxUtils.bind(this,(function(t){for(var e=0;e<t.items.length;e++)mxUtils.bind(this,(function(i){i.title=i.originalFilename,i.getXml=mxUtils.bind(this,(function(t,e){this.ui.drive.getXmlFile(i,mxUtils.bind(this,(function(i){t(i.getData())})),e)})),i.getUrl=mxUtils.bind(this,(function(t){return this.ui.getUrl(window.location.pathname+"?rev="+i.id+"&chrome=0&nav=1&layers=1&edit=_blank"+(null!=t?"&page="+t:""))+window.location.hash}))}))(t.items[e]);i(t.items)})),t)},DriveFile.prototype.getLatestVersion=function(i,t){this.ui.drive.getFile(this.getId(),i,t,!0)},DriveFile.prototype.getChannelId=function(){var i=this.ui.drive.getCustomProperty(this.desc,"channel");return null!=i&&(i="G-"+this.getId()+"."+i),i},DriveFile.prototype.getChannelKey=function(){return this.ui.drive.getCustomProperty(this.desc,"key")},DriveFile.prototype.getLastModifiedDate=function(){return new Date(this.desc.modifiedDate)},DriveFile.prototype.getDescriptor=function(){return this.desc},DriveFile.prototype.setDescriptor=function(i){this.desc=i},DriveFile.prototype.getDescriptorSecret=function(i){return this.ui.drive.getCustomProperty(i,"secret")},DriveFile.prototype.setDescriptorRevisionId=function(i,t){i.headRevisionId=t},DriveFile.prototype.getDescriptorRevisionId=function(i){return i.headRevisionId},DriveFile.prototype.getDescriptorEtag=function(i){return i.etag},DriveFile.prototype.setDescriptorEtag=function(i,t){i.etag=t},DriveFile.prototype.loadPatchDescriptor=function(i,t){this.ui.drive.executeRequest({url:"/files/"+this.getId()+"?supportsAllDrives=true&fields="+this.ui.drive.catchupFields},mxUtils.bind(this,(function(t){i(t)})),t)},DriveFile.prototype.patchDescriptor=function(i,t){i.headRevisionId=t.headRevisionId,i.modifiedDate=t.modifiedDate,DrawioFile.prototype.patchDescriptor.apply(this,arguments)},DriveFile.prototype.loadDescriptor=function(i,t){this.ui.drive.loadDescriptor(this.getId(),i,t)},DriveFile.prototype.commentsSupported=function(){return!0},DriveFile.prototype.getComments=function(i,t){var e=this.ui.getCurrentUser();function s(i,t,n){if(t.deleted)return null;for(var r=new DriveComment(i,t.commentId||t.replyId,t.content,t.modifiedDate,t.createdDate,"resolved"==t.status,t.author.isAuthenticatedUser?e:new DrawioUser(t.author.permissionId,t.author.emailAddress,t.author.displayName,t.author.picture.url),n),o=0;null!=t.replies&&o<t.replies.length;o++)r.addReplyDirect(s(i,t.replies[o],t.commentId));return r}this.ui.drive.executeRequest({url:"/files/"+this.getId()+"/comments"},mxUtils.bind(this,(function(t){for(var e=[],n=0;n<t.items.length;n++){var r=s(this,t.items[n]);null!=r&&e.push(r)}i(e)})),t)},DriveFile.prototype.addComment=function(i,t,e){var s={content:i.content};this.ui.drive.executeRequest({url:"/files/"+this.getId()+"/comments",method:"POST",params:s},mxUtils.bind(this,(function(i){t(i.commentId)})),e)},DriveFile.prototype.canReplyToReplies=function(){return!1},DriveFile.prototype.canComment=function(){return this.desc.canComment},DriveFile.prototype.newComment=function(i,t){return new DriveComment(this,null,i,Date.now(),Date.now(),!1,t)};