Initial commit

This commit is contained in:
Florian Bouillon 2019-03-04 22:46:07 +01:00
commit 9628c2cd42
11 changed files with 1322 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

21
LICENSE.md Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 Avior
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

1
README.md Normal file
View File

@ -0,0 +1 @@
Gestionnaire de fichier en construction!

84
coffee/renderer.coffee Normal file
View File

@ -0,0 +1,84 @@
# import Gitlab from 'gitlab'
{ ProjectBundle } = require('gitlab')
options = {
url: 'https://gitlab.com'
token: ''
}
gitlab = new ProjectBundle(options)
# this is actually a test
forceRefresh = true
user = undefined
getUser = () ->
if user is undefined or forceRefresh
user = await gitlab.Users.current()
user
projects = undefined
getProjects = () ->
console.log "loading Projects!"
if projects is undefined or forceRefresh
console.log "loading Projects!"
projects = await gitlab.Projects.all { membership: true }
console.log projects
projects
project = {}
getProject = (projectId) ->
if projectId isnt undefined
if project[projectId] is undefined or forceRefresh
project[projectId] = await (gitlab.Projects).show projectId
return project[projectId]
return undefined
projectTree = {}
getProjectTree = (projectId) ->
if projectId isnt undefined
if projectTree[projectId] is undefined or forceRefresh
projectTree[projectId] = await gitlab.Repositories.tree(projectId, { recursive: true }).catch (e) ->
console.log "pouet"
console.log ed
return projectTree[projectId]
return undefined
loadProjects = (parent) ->
for el in await getProjects()
tr = document.createElement 'tr'
name = el.name_with_namespace.split '/'
name.pop()
td = "<td>" + el.id + "</td><td>" + el.name + "</td><td>" + name.join(" -> ") + "</td>"
tr.innerHTML = td
tr.setAttribute 'data-id', el.id
tr.addEventListener 'click', (event) ->
console.log event
loadProjectTree document.querySelector(".tree"), event.target.parentNode.getAttribute("data-id")
return
parent.appendChild tr
return
loadProjectTree = (parent, projectId) ->
parent.innerHTML = ''
for el in await getProjectTree projectId
path = el.path.split "/"
path.pop()
tempParent = parent
if el.type is "tree" then element = "<ul data-path=\"" + el.name + "\"></ul>"
else element = "<li>" + el.name + "</li>"
if path.length > 1
tempParent = parent.querySelector "[data-path=\"" + path.pop() + "\"]"
tempParent.innerHTML += element
for el in parent.querySelectorAll("[data-path]")
li = document.createElement "li"
text = document.createTextNode el.getAttribute("data-path") + "/"
li.appendChild text
li.classList.add "folder"
el.parentNode.insertBefore(li, el)
return
loadProjects(document.querySelector('.projectList'))
# console.log projects

31
index.html Normal file
View File

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<link rel="stylesheet" href="./styles.css">
</head>
<body>
<main>
<table>
<thead>
<tr>
<th>File Name</th>
<th>Modified</th>
<th>Size</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</main>
<script>
// You can also require other files to run in this process
require('./renderer.js');
// getProjects();
</script>
</body>
</html>

56
main.js Normal file
View File

@ -0,0 +1,56 @@
// Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron')
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
})
// and load the index.html of the app.
mainWindow.loadFile('index.html')
// Open the DevTools.
// mainWindow.webContents.openDevTools()
// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow()
}
})
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

18
package.json Normal file
View File

@ -0,0 +1,18 @@
{
"name": "delta-file-manager",
"version": "0.1.0",
"description": "A customizable fiel manager",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"author": "Avior",
"license": "MIT",
"devDependencies": {
"electron": "^4.0.6"
},
"dependencies": {
"ts-node": "^8.0.2",
"typescript": "^3.3.3333"
}
}

2
renderer.js Normal file
View File

@ -0,0 +1,2 @@
require("ts-node").register();
require("./src/renderer");

69
src/renderer.ts Normal file
View File

@ -0,0 +1,69 @@
import { sep } from 'path';
import { Stats } from "fs";
const fs = require("fs");
import { shell } from 'electron';
const loader = document.querySelector("tbody");
const rootPath = '/';
const loadFolder = (path: string) => {
loader.innerHTML = "";
if(path != rootPath) {
let pt = path.split("/");
pt.pop();
console.log(rootPath);
console.log(pt.join("/"));
let pouet = "" == pt.join("/") ? sep : pt.join("/");
addElement("..", pouet);
}
fs.readdir(path, (err, items) => {
for (const item of items) {
console.log(path);
let it = path == "/" ? path + item : path + sep + item;
fs.stat(it, (err, stat) => {
// console.log(err);
let pth = path == "/" ? path + item : path + sep + item;
addElement(item, pth, stat);
});
}
});
}
function addElement(filename: string, path: string, stat: Stats = null) {
let mtime = stat != null ? stat.mtime : null;
let classe = stat != null ? (stat.isDirectory() ? "folder" : "file") : "folder";
if(stat != null) var month = (mtime.getUTCMonth() + 1) > 10 ? "0" + (mtime.getUTCMonth() + 1) : "" + (mtime.getUTCMonth() + 1);
else var month = "0";
let time = stat == null || stat.isDirectory() ? "--" : mtime.getUTCFullYear() + "/" + month + "/" + mtime.getUTCDate();
let bytes = stat == null || stat.isDirectory() ? "--" : formatBytes(stat.size);
let tr = document.createElement("tr");
tr.classList.add(classe);
tr.setAttribute("data-file", path);
tr.addEventListener("click", function() {
if(this.classList.contains("folder")) loadFolder(this.getAttribute("data-file"));
else loadFile(this.getAttribute("data-file"));
});
for (const el of [filename, time, bytes]) {
let td = document.createElement("td");
td.innerText = el;
tr.appendChild(td);
}
loader.appendChild(tr);
}
function formatBytes(integ: number): string {
if(integ === 0) return "0 bytes";
let sep = 1024, d = 2;
let ent = ["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"];
let f = Math.floor(Math.log(integ)/Math.log(sep));
return parseFloat((integ / Math.pow(sep, f)).toFixed(d)) + " " + ent[f];
}
function loadFile(file: string) {
shell.openItem(file);
}
loadFolder("/");

32
styles.css Normal file
View File

@ -0,0 +1,32 @@
main {
display: flex;
flex-wrap: wrap;
}
table {
width: 100%;
border-collapse: collapse;
cursor: pointer;
}
table th {
text-align: left;
}
table tr {
border-bottom: 1px solid #212121;
height: 50px;
}
table tr td:first-child {
padding-left: 60px;
background-repeat: no-repeat;
}
table tr.folder td:first-child {
background-image: url(https://image.flaticon.com/icons/svg/148/148953.svg);
}
table tr.file td:first-child {
background-image: url(https://image.flaticon.com/icons/svg/263/263103.svg)
}

1007
yarn.lock Normal file

File diff suppressed because it is too large Load Diff