Permalink
Browse files

Meta Infos zu den vorhandenen Dateien anzeigen

  • Loading branch information...
1 parent 914ef36 commit c1eef8299c10dec6c7552e64689f742756ac3fa6 Stephan committed Nov 30, 2012
View
@@ -14,4 +14,4 @@ results
npm-debug.log
node_modules
-
+files/user*
@@ -27,7 +27,8 @@ function(app, jquery, Views ) {
Localeedit.ItemModel = Backbone.Model.extend({
defaults: {
Language: 'XX',
- Value: 'Foo'
+ Value: 'Foo',
+ IsFunction: false
},
initialize: function() {
console.log('new Locale ItemModel');
@@ -113,7 +114,17 @@ function(app, jquery, Views ) {
var $text = $('<span>', {
'class' : "label label-info pull-left"
}).appendTo($fileWrapper);
- $text.html(value.name);
+ $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 $btnDelete = $('<button>', {
type : "button",
View
@@ -47,4 +47,8 @@ li.edititem {
.pull-right.loading{
margin: 20px 20px 0 0;
display: none;
+}
+
+.file-list-wrapper span{
+ margin: 0 50px 0 0;
}
@@ -1,3 +1,3 @@
<span class="label"><%= model.Language %></span>
- <input class="translation input-xxlarge" type="text" value='<%= model.Value %>'></input>
+ <input class="translation input-xxlarge" type="text" <%= model.IsFunction ? 'disabled' : '' %> value='<%= model.Value %>'></input>

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -2,7 +2,7 @@ var fs = require('fs')
, path = require('path')
, vm = require('vm')
, util = require('util')
- , linq = require('linq')
+ , mv = require('mv')
, sandbox = {
Intranet: {
Locale: {},
@@ -51,47 +51,74 @@ exports.GetUserFiles = function(req, res) {
console.log('Retrieving UserFiles: ');
fs.readdir(dirName, function(err, files){
- var jsOnlyFiles = [];
+
+ var jsOnlyFiles = [];
+ var jsOnlyFilesWithMetaInfo = [];
+
+ var doResponse = function() {
+ res.writeHead(200, { 'Content-Type': 'application/json' });
+ res.write(JSON.stringify(
+ jsOnlyFilesWithMetaInfo.map(function (file)
+ {
+ return { url: '/files/' + 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 ){
- jsOnlyFiles.push(file);
+ jsOnlyFiles.push(file);
}
}
- res.writeHead(200, { 'Content-Type': 'application/json' });
- res.write(JSON.stringify(
- jsOnlyFiles.map(function (file)
- {
- return { url: '/files/' + file,
- name: file,
- deleteUrl: req.originalUrl + file }; })
- ));
- res.end();
+ // anreichern mit meta infos
+ for (var i in jsOnlyFiles) {
+ var file = jsOnlyFiles[i];
+ var statsDone = 0;
+
+ fs.stat(dirName+'/' + file, function(err, stats){
+
+ jsOnlyFilesWithMetaInfo.push({
+ Name: file,
+ mtime: stats.mtime,
+ size: stats.size
+ });
+ statsDone +=1;
+ if(statsDone === jsOnlyFiles.length){
+ doResponse();
+ }
+ });
+
+
+ }
});
};
exports.SaveLocales = function(req, res) {
var data = "",
- jsonData ;
+ jsonData ,
+ dirName = getUserFolder(req);
+
req.addListener('data', function(chunk) { data += chunk; });
req.addListener('end', function() {
jsonData = JSON.parse(data);
- saveLocaleJsonToFiles(jsonData,function(){
+ saveLocaleJsonToFiles(jsonData, dirName, function(){
res.writeHead(200, {'content-type': 'text/plain' });
res.end()
})
});
};
-function saveLocaleJsonToFiles = function(data, callback){
-
- callback();
-}
exports.DeleteUserFile = function(req, res) {
var dirName = getUserFolder(req);
@@ -164,33 +191,203 @@ function parseLocaleJs (array) {
function toMultiLocaleItem (Locales){
var multiLocaleList = {};
+ var existingLanguages = [];
+ var allKeys = {};
+ var currentValue = "";
+ // SaveAll Languages
+ for (var language in Locales) {
+ if(existingLanguages.indexOf(language) == -1 ){
+ existingLanguages.push(language);
+ }
+ }
for (var language in Locales) {
var lang = Locales[language];
- for (var prop in lang) {
- var existing = multiLocaleList[prop] || {Values: []};
+ for (var key in lang) {
+ var existing = multiLocaleList[key] || {Values: []};
+ currentValue = lang[key].toString();
var localValue = { Language: language,
- Value: lang[prop].toString()
+ Value: currentValue,
+ IsFunction: currentValue.substring(0,10).indexOf('function') != -1
}
existing.Values.push(localValue);
- multiLocaleList[prop] = existing;
+ multiLocaleList[key] = existing;
}
}
var multiLocaleArray = [];
- for (var prop in multiLocaleList) {
- var v = multiLocaleList[prop];
+ //Object Literal zu array umwandeln
+ // prüfen ob alle schlüssel in allen sprachen vorhanden sind
+ for (var key in multiLocaleList) {
+ var v = multiLocaleList[key];
+
+
+ if(v.Values.length !== existingLanguages.length) {// es scheint als ob sprachen fehlen
+
+ for (var l in existingLanguages)
+ {
+ var exists = false;
+ var lang = existingLanguages[l];
+ for (var value in v.Values) {
+ var currentValue = v.Values[value];
+
+ if(currentValue.Language == lang) {
+ exists = true;
+ }
+ }
+ if(!exists) {
+ v.Values.push({
+ Language: lang,
+ Value: "!UNDEFINED-LOCALE"
+ })
+ }
+ }
+ }
+
multiLocaleArray.push({
- LocaleKey: prop,
+ LocaleKey: key,
LocaleValues: v.Values
});
}
return multiLocaleArray;
+}
+
+
+function moveExistingFilesToBackUpFolder(folder, callback){
+
+ fs.readdir(folder, function(err, files){
+
+ var fileOnlyNames = [];
+
+ for (var i in files) {
+
+ var fileName = folder + '/' + files[i];
+ var stats = fs.lstatSync(fileName);
+
+ if (stats.isFile()) {
+ fileOnlyNames.push(
+ {
+ Path:fileName,
+ Name:files[i]
+ });
+ }
+ }
+
+ console.log('found the following files :');
+ console.log(fileOnlyNames);
+ var done = 0;
+
+ var d = new Date();
+ var outPutFolder = folder+ '/' + d.getFullYear().toString()+ d.getMonth()+ d.getDay()+ d.getHours()+ d.getMinutes() + + d.getSeconds()+ "_backUp";
+ fs.mkdir(outPutFolder, function (err) {
+ for (var i in fileOnlyNames) {
+
+ var fname = fileOnlyNames[i];
+
+ console.log('-----------------------------------');
+ console.log('moving : ' +fname.Path);
+ console.log('to : ' +outPutFolder+ '/' +fname.Name);
+ console.log('-----------------------------------');
+
+ // var is = fs.createReadStream(fname.Path)
+ // var os = fs.createWriteStream(outPutFolder+ '/' +fname.Name);
+
+ // is.pipe(os);
+ // fs.unlinkSync(fname.Path);
+
+ mv(fname.Path, outPutFolder+ '/' +fname.Name, function(err) {
+ // done. it tried fs.rename first, and then falls back to
+ // piping the source file to the dest file and then unlinking
+ // the source file.
+ });
+
+ }
+ callback();
+ });
+
+ });
}
+function saveLocaleJsonToFiles (data, dirName, callback){
+
+ var locales = {};
+
+ var partialFileName = "Intranet.Locale.";
+
+ for( var i = 0 ; i < data.length; i++){
+ var obj = data[i];
+ var localeKey = obj.LocaleKey;
+ for( var j = 0 ; j < obj.LocaleValues.length; j++)
+ {
+ var currentValue = obj.LocaleValues[j].Value;
+ var currentLanguage = obj.LocaleValues[j].Language;
+ locales[currentLanguage] = locales[currentLanguage] || {};
+ locales[currentLanguage][localeKey] = currentValue;
+ };
+ };
+
+ function procceed(){
+ var outputString =""
+
+ for (var lang in locales)
+ {
+ var current = locales[lang];
+
+ outputString = "";
+ outputString += "Intranet.namespace('Intranet.Locale."+ lang + "');\r\n";
+ outputString += "Intranet.Locale."+ lang + " = {\r\n";
+
+ for (var k in current)
+ {
+ var localeValue = current[k];
+ var hasSingleQuoteInside = localeValue.indexOf('\'') != -1;
+
+
+ if(localeValue.substring(0,10).indexOf('function') == -1)
+ {
+ // Wenn der String single qoutes innerhalb hat, wert in double qoutes einpassen
+ // ansonsten singleqoutes
+ if(hasSingleQuoteInside){
+ outputString += k + ": \"" + localeValue.replace("\n","\\n") + "\",\r\n";
+ }else{
+ outputString += k + ": '" + localeValue.replace("\n","\\n") + "',\r\n";
+ }
+
+ }else{
+ // wir haben eine function! nicht in qoutes einpassen!!!
+ outputString += k + ": " + localeValue + ",\r\n";
+ }
+
+ }
+
+ // remove last comma
+ outputString = outputString.substring(0, outputString.length - 3) + "\r\n";
+ outputString += " };";
+
+
+ var filename = dirName + '/'+ partialFileName + lang + ".js";
+ fs.writeFile(filename, outputString, function(err) {
+ if(err) {
+ console.log(err);
+ } else {
+ console.log("The file was saved! : " + filename);
+ }
+ });
+ }
+ callback();
+ }
+
+ // save a backUp
+ moveExistingFilesToBackUpFolder(dirName,procceed);
+
+
+
+
+
+}
exports.GetCurrentWorkingLocales = function(req, res) {
var dirName = getUserFolder(req);
var locales = [];
@@ -214,12 +411,34 @@ exports.GetCurrentWorkingLocales = function(req, res) {
var done = 0;
for (var i in fileOnlyNames) {
- var fileName = dirName + '/' + files[i];
- var stats = fs.lstatSync(fileName);
+ var fileName = fileOnlyNames[i];
fs.readFile(fileName, function handleFile(err, data) {
+
+ // var ar = data.split('\n');
+ // var part = '';
+ // var key = '';
+
+ // for(var i = 0; i < length; i ++) {
+ // var curent = ar[i];
+ // var indexofColon = current.indexOf(':');
+ // if(indexofColon !== -1) {
+ // key = current.substring(0, indexofColon -1 );
+ // part = current.substring(indexofColon+1);l
+ // }else{
+
+ // }
+ // }
+
+ intranetLocaleContext = vm.createContext(sandbox);
vm.runInContext(data, intranetLocaleContext);
+
+ /*
+ {DE:{ Key1 : 'Value',
+ Key2 : 'Value'
+ }}*/
+
multiLocaleItem = toMultiLocaleItem(intranetLocaleContext.Intranet.Locale);
done += 1;
Oops, something went wrong.

0 comments on commit c1eef82

Please sign in to comment.