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);
|
||||
|
89
app/main.js
89
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,25 +87,9 @@ function getArrayObjectByKey(array, key, value, defaultKeyValue) {
|
||||
return defaultKeyValue ? o[0][defaultKeyValue] : o[0];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
function createWindow() {
|
||||
// Create the browser window.
|
||||
win = new BrowserWindow({width: 800, height: 600});
|
||||
win.setMenu(null);
|
||||
|
||||
// and load the index.html of the app.
|
||||
win.loadURL(url.format({
|
||||
pathname: path.join(__dirname, 'index.html'),
|
||||
protocol: 'file:',
|
||||
slashes: true
|
||||
}));
|
||||
|
||||
electronLocalshortcut.register(win, 'F12', () => {
|
||||
win.webContents.toggleDevTools();
|
||||
});
|
||||
|
||||
win.webContents.on('did-finish-load', () => {
|
||||
function loadRepoPage() {
|
||||
win.webContents.send('repoDir', repoDir);
|
||||
|
||||
getLfsFileList(repoDir, (err, files) => {
|
||||
@@ -137,8 +122,51 @@ function createWindow() {
|
||||
win.webContents.send('fileList', allFiles);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function createWindow() {
|
||||
// Create the browser window.
|
||||
win = new BrowserWindow({width: 800, height: 600});
|
||||
win.setMenu(null);
|
||||
|
||||
// and load the index.html of the app.
|
||||
win.loadURL(url.format({
|
||||
pathname: path.join(__dirname, 'index.html'),
|
||||
protocol: 'file:',
|
||||
slashes: true
|
||||
}));
|
||||
|
||||
electronLocalshortcut.register(win, 'F12', () => {
|
||||
win.webContents.toggleDevTools();
|
||||
});
|
||||
}
|
||||
|
||||
win.webContents.on('did-finish-load', () => {
|
||||
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