mirror of
https://github.com/S2-/gitlit
synced 2025-08-02 12:20:05 +02:00
add folder drag&drop functionality
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
if (files && files.length > 0) {
|
||||
$('.files-table-container').html(gitlit.templates.files({files: files}));
|
||||
sorttable.makeSortable($('.js-filestable')[0]);
|
||||
var myTH = document.getElementsByTagName("th")[0];
|
||||
var myTH = document.getElementsByTagName('th')[0];
|
||||
sorttable.innerSortFunction.apply(myTH, []);
|
||||
} else {
|
||||
$('.files-table-container').html(gitlit.templates.noGitLfsFiles());
|
||||
@@ -17,6 +17,7 @@
|
||||
});
|
||||
|
||||
ipcRenderer.on('repoDir', (event, repoDir) => {
|
||||
$('.js-container').html(gitlit.templates.main());
|
||||
$('.js-repo-dir').text('current repo dir: ' + repoDir).show();
|
||||
});
|
||||
|
||||
@@ -87,8 +88,21 @@
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('drop', (ev) => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
|
||||
if (ev.originalEvent.dataTransfer.files && ev.originalEvent.dataTransfer.files.length > 0) {
|
||||
ipcRenderer.send('restart', ev.originalEvent.dataTransfer.files[0].path);
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('dragover', (ev) => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
});
|
||||
|
||||
//startup
|
||||
PNotify.defaults.styling = 'bootstrap4'; // Bootstrap version 4
|
||||
$('.js-container').html(gitlit.templates.main());
|
||||
|
||||
})(jQuery);
|
||||
|
119
app/main.js
119
app/main.js
@@ -9,7 +9,8 @@ const args = require('minimist')(process.defaultApp ? process.argv.slice(3) : pr
|
||||
}
|
||||
});
|
||||
|
||||
const repoDir = path.resolve(path.normalize(args._.join(' ')));
|
||||
let win;
|
||||
let repoDir = path.resolve(path.normalize(args._.join(' ')));
|
||||
let repoRootDir = repoDir;
|
||||
|
||||
function getLfsFileList(dir, cb) {
|
||||
@@ -86,7 +87,42 @@ function getArrayObjectByKey(array, key, value, defaultKeyValue) {
|
||||
return defaultKeyValue ? o[0][defaultKeyValue] : o[0];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
function loadRepoPage() {
|
||||
win.webContents.send('repoDir', repoDir);
|
||||
|
||||
getLfsFileList(repoDir, (err, files) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
|
||||
win.webContents.send('isNoGitLfsRepo', repoDir);
|
||||
return;
|
||||
}
|
||||
getLfsLocks(repoDir, (err, lockedFiles) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
|
||||
win.webContents.send('isNoGitLfsRepo', repoDir);
|
||||
return;
|
||||
}
|
||||
let allFiles = [];
|
||||
let repoDirWithoutRoot = repoDir === repoRootDir ? '' : repoDir.replace(path.normalize(repoRootDir + '/'), '');
|
||||
|
||||
files.forEach((file) => {
|
||||
const t = {
|
||||
file: file,
|
||||
lockedBy: getArrayObjectByKey(lockedFiles, 'file', path.normalize(repoDirWithoutRoot ? repoDirWithoutRoot + '/' + file : file), 'lockedBy'),
|
||||
id: getArrayObjectByKey(lockedFiles, 'file', path.normalize(repoDirWithoutRoot ? repoDirWithoutRoot + '/' + file : file), 'id')
|
||||
};
|
||||
|
||||
allFiles.push(t);
|
||||
});
|
||||
|
||||
win.webContents.send('fileList', allFiles);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function createWindow() {
|
||||
// Create the browser window.
|
||||
@@ -105,40 +141,32 @@ function createWindow() {
|
||||
});
|
||||
|
||||
win.webContents.on('did-finish-load', () => {
|
||||
win.webContents.send('repoDir', repoDir);
|
||||
|
||||
getLfsFileList(repoDir, (err, files) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
|
||||
win.webContents.send('isNoGitLfsRepo', repoDir);
|
||||
return;
|
||||
}
|
||||
getLfsLocks(repoDir, (err, lockedFiles) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
|
||||
win.webContents.send('isNoGitLfsRepo', repoDir);
|
||||
return;
|
||||
}
|
||||
let allFiles = [];
|
||||
let repoDirWithoutRoot = repoDir === repoRootDir ? '' : repoDir.replace(path.normalize(repoRootDir + '/'), '');
|
||||
|
||||
files.forEach((file) => {
|
||||
const t = {
|
||||
file: file,
|
||||
lockedBy: getArrayObjectByKey(lockedFiles, 'file', path.normalize(repoDirWithoutRoot ? repoDirWithoutRoot + '/' + file : file), 'lockedBy'),
|
||||
id: getArrayObjectByKey(lockedFiles, 'file', path.normalize(repoDirWithoutRoot ? repoDirWithoutRoot + '/' + file : file), 'id')
|
||||
};
|
||||
|
||||
allFiles.push(t);
|
||||
});
|
||||
|
||||
win.webContents.send('fileList', allFiles);
|
||||
});
|
||||
});
|
||||
loadRepoPage();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function startup(cb) {
|
||||
exec('git rev-parse --show-toplevel', {
|
||||
maxBuffer: 1024 * 1024,
|
||||
cwd: repoDir
|
||||
},
|
||||
(error, stdout, stderr) => {
|
||||
if (error) {
|
||||
if (win) {
|
||||
win.webContents.send('isNoGitLfsRepo', repoDir);
|
||||
}
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
if (stdout) {
|
||||
repoRootDir = path.normalize(stdout.replace(/\n/g, ''));
|
||||
}
|
||||
|
||||
if (cb) {
|
||||
cb();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
ipcMain.on('unlock', (event, file) => {
|
||||
exec('git lfs unlock "' + file + '"', {
|
||||
@@ -187,22 +215,13 @@ ipcMain.on('lock', (event, file) => {
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on('restart', (event, newRepoDir) => {
|
||||
repoDir = newRepoDir;
|
||||
startup(loadRepoPage);
|
||||
});
|
||||
|
||||
app.on('ready', () => {
|
||||
exec('git rev-parse --show-toplevel', {
|
||||
maxBuffer: 1024 * 1024,
|
||||
cwd: repoDir
|
||||
},
|
||||
(error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
if (stdout) {
|
||||
repoRootDir = path.normalize(stdout.replace(/\n/g, ''));
|
||||
}
|
||||
|
||||
createWindow();
|
||||
});
|
||||
startup(createWindow);
|
||||
});
|
||||
|
||||
app.on('window-all-closed', function() {
|
||||
|
Reference in New Issue
Block a user