/* * Copyright 2007-2011 Charles du Jeu * This file is part of AjaXplorer. * * AjaXplorer 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. * * AjaXplorer 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 AjaXplorer. If not, see . * * The latest code can be found at . * Description : Simple display of SVN logs. */ Class.create("SVNLogger", { initialize:function(form){ this.element = form.select('[id="svnlog_box"]')[0]; this.element.up('div.dialogContent').setStyle({padding:0}); this.element.setStyle({ height:'315px', position:'relative' }); this.versionsDm = new AjxpDataModel(true); this.versionsRoot = new AjxpNode("/", false, "Versions", "folder.png"); this.versionsDm.setRootNode(this.versionsRoot); this.container = this.element; /* this.container = new Element('div', { style:"height:310px;overflow:auto;" }); this.element.insert(this.container); */ this.template = new Template('
#{dateString} : #{date}     #{revString} : #{revision}     #{authString} : #{author}
#{message}
#{downloadLink}
'); this.downloadTemplate = new Template('#{downloadString}'); this.revertTemplate = new Template('#{revertString}'); this.compareTemplate = new Template('#{revertString}'); this.switchTemplate = new Template('#{switchString}'); this.revMessage = MessageHash[243]; this.authorMessage = MessageHash[244]; this.dateMessage = MessageHash[245]; this.messMessage = MessageHash[246]; this.downMessage = MessageHash[88]; this.revertMessage = "Revert"; this.confirmRevertMessage = "This will create a new version of the file with the content of this previous version. Are you sure?"; this.compareMessage = "Compare"; this.switchMessage = MessageHash['meta.svn.3']; if(!$('svndownload_iframe')){ $('hidden_frames').insert(''); } }, open: function(currentRep){ var selection = ajaxplorer.getUserSelection(); if(currentRep || selection.isEmpty()){ var ajxpNode = ajaxplorer.getContextNode(); }else{ var ajxpNode = selection.getUniqueNode(); } this.fileName = ajxpNode.getPath(); this.isFile = ajxpNode.isLeaf(); this.currentFileMetadata = ajxpNode.getMetadata(); if(this.isFile){ this.filesList = new FilesList(this.element, { dataModel:this.versionsDm, columnsDef:[{attributeName:"ajxp_label", messageId:1, sortType:'String'}, {attributeName:"revision", messageString:'#', sortType:'Number'}, {attributeName:"revision_log", messageString:'Message', sortType:'String'}, {attributeName:"revision_date", messageId:4, sortType:'String'}, {attributeName:"author", messageString:'Author', sortType:'String'}, {attributeName:"links", messageString:'Actions', sortType:'String'} ], defaultSortTypes:["String", "String", "String", "String", "String", "String"], columnsTemplate:"svnlog_file", selectable: false, draggable: false, replaceScroller:true }); }else{ this.filesList = new FilesList(this.element, { dataModel:this.versionsDm, columnsDef:[{attributeName:"revision", messageString:'#', sortType:'Number'}, {attributeName:"revision_log", messageString:'Message', sortType:'String'}, {attributeName:"revision_date", messageId:4, sortType:'String'}, {attributeName:"author", messageString:'Author', sortType:'String'}, {attributeName:"links", messageString:'Actions', sortType:'String'} ], defaultSortTypes:["Number", "String", "String", "String", "String"], columnsTemplate:"svnlog_folder", selectable: false, draggable: false, replaceScroller:true }); } var connexion = new Connexion(); connexion.addParameter('get_action', 'svnlog'); connexion.addParameter('file', this.fileName); connexion.onComplete = this.displayResponse.bind(this); this.setOnLoad(); connexion.sendAsync(); }, addEntry:function(index, revision,author,date,message){ var separator = '||'; if(message.indexOf(separator)>-1){ var split = message.split(separator); author = split[1]; if( this.isFile && split[2].toLowerCase().startsWith("rename") && split[3]){ var pfn = getBaseName($A(split[3].split("item:")).last()); if(pfn.indexOf(".") !== -1) var previousFileName = pfn; } message = ""+split[2].toUpperCase()+""; if(split[3]){ message += " : "+split[3]; } } var dateParts = date.split('\.'); date = dateParts[0].replace("T", " "); var skipSwitch = false; var cssStyle = ''; if(this.currentRev){ if(this.currentRev.firstChild.nodeValue == revision){ skipSwitch = true; cssStyle = "background-color:#efe;"; } }else if(this.revisionRange){ var start = parseInt(this.revisionRange.getAttribute('start')); var end = parseInt(this.revisionRange.getAttribute('end')); var rev = parseInt(revision); if(start <= rev && rev <= end){ cssStyle = "background-color:#fee;"; } } var dLink = (this.isFile?this.downloadTemplate.evaluate({ fileName:this.fileName, revision:revision, downloadString:this.downMessage }):(!skipSwitch?this.switchTemplate.evaluate({ revision:revision, switchString:this.switchMessage }):'')); if(this.isFile){ var dLink2 = this.revertTemplate.evaluate({ fileName:this.fileName, revision:revision, revertString:this.revertMessage, confirmRevertString:this.confirmRevertMessage }); var dLink3 = this.compareTemplate.evaluate({ fileName:this.fileName, revision:revision, revertString:this.compareMessage }); dLink = dLink + " | " + dLink2 + " | " + dLink3; } if(this.filesList){ var node = new AjxpNode("/"+revision, true, "Revision "+revision, "mime_empty.png"); if(this.previousFileName){ node.getMetadata().set('text', this.previousFileName); }else{ node.getMetadata().set('text', getBaseName(this.fileName)); } node.getMetadata().set('icon', this.currentFileMetadata.get('icon')); node.getMetadata().set('revision_log', message); node.getMetadata().set('revision_date', date.split(' ')[0]); node.getMetadata().set('revision', revision); node.getMetadata().set('author', author); if(index > 0){ node.getMetadata().set('links', dLink); }else{ node.getMetadata().set('links', ""); } this.versionsRoot.addChild(node); }else{ this.container.insert(this.template.evaluate({ revision:revision, author:author, date:date, message:message, downloadLink:dLink, cssStyle:cssStyle, revString:this.revMessage, authString:this.authorMessage, dateString:this.dateMessage, messString:this.messMessage })); } if(previousFileName) this.previousFileName = previousFileName; }, displayResponse: function(transport){ var oXmlDoc = transport.responseXML; if(oXmlDoc == null || oXmlDoc.documentElement == null) return; var root = oXmlDoc.documentElement; if(!root.childNodes.length) return; var logEntries = XPathSelectNodes(root, "log/logentry"); this.currentRev = XPathSelectSingleNode(root, "current_revision"); this.revisionRange = XPathSelectSingleNode(root, "revision_range"); try{ for(var i=0; i