Skip to content

Commit

Permalink
revisions folder anzeigen
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan committed Dec 13, 2012
1 parent ddd3c6c commit 8bec06d
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 21 deletions.
63 changes: 63 additions & 0 deletions app/modules/localeEdit/localeEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,70 @@ function(app, jquery, Views ) {
})

};
Localeedit.InitRevisionListUi = function(){
$('.revisons-list-wrapper').html('');
var $fileListWrapper = $('.revisons-list-wrapper')
return $.ajax({
url: '/api/getCurrentRevisions'
}).success(function(data) {
$.each(data,function(index, value){
var $fileWrapper = $('<div>',{
'class': ' well well-large file'
}).appendTo($fileListWrapper);

var $text = $('<span>', {
'class' : "label label-info pull-left"
}).appendTo($fileWrapper);
$text.html('Name: ' + value.name);

var $text = $('<span>', {
'class' : "label label-info pull-left"
}).appendTo($fileWrapper);
$text.html('Änderungsdatum: ' + value.lastChange);

var $text = $('<span>', {
'class' : "label label-info pull-left"
}).appendTo($fileWrapper);
$text.html('Größe: ' + value.size);

var $btnDownlaod = $('<button>', {
type : "button",
'class' : "pull-right btn btn-primary",
'data-loading-text' : "downloading"
}).appendTo($fileWrapper);
$btnDownlaod.html('Download');

$btnDownlaod.click(function(){
window.open(value.url, 'Download ' + value.name);
});

var $btnDelete = $('<button>', {
type : "button",
'class' : "pull-right btn btn-primary",
'data-loading-text' : "deleteing"
}).appendTo($fileWrapper);
$btnDelete.html('Löschen');
$btnDelete.click(function(){
$.ajax({ url: '/api/deleteUserFile/',
type: 'POST',
data: {
Filename: value.name
}
}).success(function(data){
Localeedit.InitFileListUi();
});
});

})
})
.fail(function () {
$('<span class="alert alert-error"/>')
.text('file manager currently unavaiable - ' +
new Date())
.appendTo('.revisons-list-wrapper');
});

};
Localeedit.InitFileListUi = function() {
$('.file-list-wrapper').html('');
var $fileListWrapper = $('.file-list-wrapper')
Expand Down
5 changes: 5 additions & 0 deletions app/modules/localeEdit/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ function(app, LocaleEdit, Backbone) {
manage: true
});

Views.Revisions = Backbone.View.extend({
template: 'app/templates/localeedit/revisions',
manage: true
});

Views.EditFilter = Backbone.View.extend({
events: {
"keyup #keySearchTask" : "KeySearch",
Expand Down
37 changes: 27 additions & 10 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,23 @@ function(app,LocaleEdit,jquery) {
"": "index",
"index": "index",
"edit": "edit",
"overview": "overview"
"overview": "overview",
"revisions" : "revisions"
},
overview: function() {
index: function() {
jquery('#loadIndicator').show();
app.useLayout('main').setViews({
'#stage': new LocaleEdit.Views.Upload()
}).render()
.done(function(){
jquery.when(LocaleEdit.InitUi())
.done(function(){
jquery('ul.nav li').removeClass('active');
jquery('ul.nav a[href="#index"]').parent().addClass('active');
jquery('#loadIndicator').fadeOut('slow');
});
});
}, overview: function() {
jquery('#loadIndicator').show();
app.useLayout('main').setViews({

Expand All @@ -32,20 +46,23 @@ function(app,LocaleEdit,jquery) {
});
});
},
index: function() {
revisions: function() {
jquery('#loadIndicator').show();
app.useLayout('main').setViews({
'#stage': new LocaleEdit.Views.Upload()

'#stage': new LocaleEdit.Views.Revisions()
}).render()
.done(function(){
jquery.when(LocaleEdit.InitUi())
.done(function(){
.done(function() {
jquery.when(LocaleEdit.InitRevisionListUi())
.done(function(){

jquery('ul.nav li').removeClass('active');
jquery('ul.nav a[href="#index"]').parent().addClass('active');
jquery('ul.nav a[href="#revisions"]').parent().addClass('active');
jquery('#loadIndicator').fadeOut('slow');
});
});
});
});
},

edit: function() {
jquery('#loadIndicator').show();
var collection = new LocaleEdit.Collection();
Expand Down
10 changes: 10 additions & 0 deletions app/templates/localeedit/revisions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class="container">
<div class="page-header">
<h1>Revision-list</h1>
</div>
<blockquote>
<p>This overview shows your backup folder. You can delete these folders or switch to the content of a folder.
</p>
</blockquote>
<br>
<div class="revisons-list-wrapper"></div>
12 changes: 1 addition & 11 deletions edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,8 @@
<li class="active"><a href="#index">Upload</a></li>
<li><a href="#overview">Übersicht</a></li>
<li><a href="#edit">Editieren</a></li>
<li><a href="#revisions">REVISIONEN</a></li>
<li class="pull-right" style="margin: 0 60px 0 0;"><a href="logout" data-bypass>LogOut</a></li>
<!-- <li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">FrontEnd<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Twitter Bootstrap</a></li>
<li><a href="#">Google Plus API</a></li>
<li><a href="#">HTML5</a></li>
<li class="divider"></li>
<li><a href="#">Examples</a></li>
</ul>
</li> -->

</ul>
</li>
</ul>
Expand Down
47 changes: 47 additions & 0 deletions localeEditFileManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,53 @@ exports.GetUserFiles = function(req, res) {
});
};

exports.GetCurrentRevisions = function(req, res) {
var dirName = getUserFolder(req);
console.log('Retrieving UserFiles: ');
fs.readdir(dirName, function(err, files){



var dirs = [];
var dirsWithMetaInfo = [];

var doResponse = function() {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.write(JSON.stringify(
dirsWithMetaInfo.map(function (file)
{
return { url: '/files/user_' + req.session.passport.user + '/' + file.Name,
name: file.Name,
lastChange: file.mtime,
size: file.size,
deleteUrl: req.originalUrl + file }; })
));
res.end();
};

// nur die js Dateien ohne Ordner
for (var i in files) {
var file = files[i];
if(file.indexOf('js') === -1 ){
dirs.push(file);
}
}

// anreichern mit meta infos
for (var i in dirs) {
var dir = dirs[i];
var statsDone = 0;

var stats = fs.statSync(dirName+'/' + dir);
dirsWithMetaInfo.push({
Name: dir,
mtime: stats.mtime,
size: stats.size
});
}
doResponse();
});
};

exports.SaveLocales = function(req, res) {

Expand Down
1 change: 1 addition & 0 deletions main.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<li class="active"><a href="#index">UPLOAD</a></li>
<li><a href="#overview">OVERVIEW</a></li>
<li><a href="#edit">EDIT</a></li>
<li><a href="#revisions">REVISIONEN</a></li>
<li class="pull-right" style="margin: 0 60px 0 0;"><a href="logout" data-bypass>LOGOUT</a></li>
<!-- <li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">FrontEnd<b class="caret"></b></a>
Expand Down
2 changes: 2 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ app.get('/', ensureAuthenticated, indexRequest);
app.get('/index', ensureAuthenticated, indexRequest);
app.get('/edit', ensureAuthenticated, indexRequest);
app.get('/overview', ensureAuthenticated, indexRequest);
app.get('/revisions', ensureAuthenticated, indexRequest);

app.get('/upload', function indexRequest (req, res){
res.writeHead(200, {'Content-Type': 'text/html'});
Expand Down Expand Up @@ -177,6 +178,7 @@ app.get('/files/*', function(req, res){

//get a array of uploaded js files which represent the basis for our future work
app.get('/api/currentfiles', filemanager.GetUserFiles);
app.get('/api/getCurrentRevisions', filemanager.GetCurrentRevisions);
//get the locales as json array of locale objects
app.get('/api/getworkinglocales', filemanager.GetCurrentWorkingLocales);
app.post('/api/deleteUserFile',express.bodyParser(), filemanager.DeleteUserFile);
Expand Down

0 comments on commit 8bec06d

Please sign in to comment.