implemented bootstrap for easier formatting.

implemented view factory for easier automation of file cards.
build-validation
David Tookey 5 years ago
parent b4a96c3f18
commit 064dae73a7

@ -1,32 +0,0 @@
.normal-header{
font-size: 19pt;
text-align: center;
}
body{
background: #ffffff;
}
.thumbnail{
width: 40px;
height: 40px;
}
.file-table{
border: 1px solid black;
border-radius: 3px;
}
.red-list{
background: red;
}
.file-row {
cursor: pointer;
}
.file-row:hover{
background: #c0c0c0;
}
.file-row-cell{
padding-left: 5px;
padding-right: 5px;
}

@ -3,7 +3,10 @@
<head>
<meta charset="UTF-8">
<title>Landing page</title>
<link rel="stylesheet" type="text/css" href="default.css">
<link rel="stylesheet" href="../../node_modules/bootstrap/dist/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="styles/default.css">
<!-- <meta http-equiv="Content-Security-Policy" content="script-src 'self';">-->
</head>
<body>
<div class="normal-header">
@ -14,19 +17,10 @@
<br>
<a href="second.html">Go to the second page</a>
<br><br>
<ul>
<li class="red-list">a</li>
<li class="red-list">b</li>
<li class="red-list">c</li>
<li>d</li>
</ul>
<br><br>
<input type="button" id="btnLaunch" value="Launch Doc">
<br><br>
<input type="button" id="btnVideo" value="Launch Video">
<br><br>
<input type="button" id="btnWeb" value="Launch Website">
</body>
<script>let $ = require('jquery');</script>
<script>require('bootstrap')</script>
<script>require('popper.js')</script>
<script src="scripts/index_app.js"></script>
</html>

@ -1,48 +1,10 @@
const shell = require('electron').shell;
const path = require('path');
const template = require(path.join(appDir, 'templates'))
const fileutils = require(path.join(appDir, 'fileutils'))
const factory = require(path.join(appDir, 'viewFactory'))
let config = new fileutils.Configurator();
let fu = new fileutils.FileUtils();
function launchDocument(filename) {
let fullPath = fu.getPathToDocument(filename);
console.log(fullPath);
shell.openItem(fullPath);
}
function launchWebsite(url) {
shell.openItem(url);
function loadDocuments() {
let container = document.querySelector("#container");
let fileName = "voicemail-and-vacation-responder.pdf";
factory.buildFileCard(fileName, container, true)
}
function loadDocuments(){
let objs = [{
imagepath: fu.getPathToImage("pdf-icon.svg"),
filename: "voicemail-and-vacation-responder.pdf",
filnamesolid: "voicemail-and-vacation-responder",
buttonCallback: `launchDocument(\"voicemail-and-vacation-responder.pdf\");`
}]
template.loadTemplate("file-card", objs, (rendered) => {
for (let i = 0, l = rendered.length; i < l; i++) {
let snippet = rendered[i]
console.log(snippet)
document.querySelector("#container").innerHTML += snippet;
}
})
}
document.querySelector('#btnLaunch').addEventListener('click', () => {
});
document.querySelector('#btnVideo').addEventListener('click', () => {
template.loadTemplate("launch video")
});
document.querySelector('#btnWeb').addEventListener('click', () => {
launchWebsite("https://gmail.com")
});
loadDocuments();

@ -0,0 +1,28 @@
body {
background: #ffffff;
}
.thumbnail {
width: 64px;
height: 64px;
}
.file-card{
cursor: pointer;
}
.file-card:hover {
background: #c0c0c0;
}
.debug-red {
border: 1px solid red;
}
.debug-green {
border: 1px solid green;
}
.debug-blue {
border: 1px solid blue;
}

@ -1,9 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<table class="file-table">
<tr class="file-row" onclick='{{{buttonCallback}}}'>
<td class="file-row-cell"><img class="thumbnail" src="{{{imagepath}}}" alt="File icon"></td>
<td class="file-row-cell">{{filename}}</td>
</tr>
</table>
</html>

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<div id="{{{id}}}" class="media d-inline-flex file-card mx-2">
<img class="align-self-center mr-3 py-2 thumbnail" src="{{{imagePath}}}" alt="File icon">
<div class="media-body align-self-center">
<p class="pr-3 mb-0">{{fileName}}</p>
</div>
</div>
</html>

306
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -29,14 +29,16 @@
"license": "Closed Source",
"dependencies": {
"electron-log": "^2.2.14",
"glob": "^7.1.0",
"highlight.js": "^9.3.0",
"update-electron-app": "^1.1.1",
"check-for-leaks": "^1.2.1",
"mustache": "^4.0.1",
"typescript": "^4.0.3",
"tslint": "^6.1.3"
"tslint": "^6.1.3",
"popper.js": "^1.16.1",
"jquery": "^3.5.1",
"bootstrap": "^4.5.3"
},
"devDependencies": {
"devtron": "^1.4.0",

@ -27,7 +27,7 @@ export class Configurator {
export class FileUtils {
getPathToView(templateName: string): string {
return path.join(this.getPathToAssets(), "views", templateName + ".html")
return path.join(this.getPathToAssets(), "views", templateName + ".mustache")
}
getPathToImage(imageName: string): string {

@ -1,5 +1,4 @@
// @ts-ignore
global.appDir = __dirname.replace("_src", "")
// @ts-ignore
window.appDir = __dirname.replace("_src", "")
console.log(__dirname.replace("_src", ""))
window.appDir = __dirname.replace("_src", "")

@ -1,12 +1,13 @@
let fs = require('fs')
let Mustache = require('mustache')
const crypto = require('crypto')
import {FileUtils} from './fileutils'
interface TemplateCallbackType {
(rendered: string[]): void
}
function loadTemplate(filename: string, objs: object[], cb: TemplateCallbackType) {
export function loadTemplate(filename: string, objs: object[], cb: TemplateCallbackType) {
let fu = new FileUtils();
let path = fu.getPathToView(filename);
fs.readFile(path, 'utf8', (err, contents) => {
@ -19,8 +20,22 @@ function loadTemplate(filename: string, objs: object[], cb: TemplateCallbackType
}
cb(results)
})
}
export function loadTemplateSingle(filename: string, obj: object, cb: (content: string, id: string) => void) {
let fu = new FileUtils();
let path = fu.getPathToView(filename);
fs.readFile(path, 'utf8', (err, contents) => {
if (err) throw err;
obj['id'] = createId(filename);
let rendered = Mustache.render(contents, obj)
cb(rendered, obj['id'])
})
}
function createId(fileName: String){
return crypto.createHash('md5').update(fileName).digest('hex');
}
module.exports = {loadTemplate}
module.exports = {loadTemplate, loadTemplateSingle}

@ -0,0 +1,55 @@
import {Configurator, FileUtils} from './fileutils'
import {loadTemplateSingle} from "./templates"
const shell = require('electron').shell;
const config = new Configurator();
const fu = new FileUtils();
class CardModel {
imagePath: string;
fileName: string;
constructor(path: string, name: string) {
this.imagePath = path;
this.fileName = name;
}
}
export function buildFileCard(filePath: string, elem: Element, append: boolean = false) {
let model = new CardModel(getImagePathFromDocumentName(filePath), fileNameToPrettyString(filePath));
loadTemplateSingle("file-card", model, (content: string, id: string) => {
if (append) {
elem.innerHTML = elem.innerHTML + content;
} else {
elem.innerHTML = content;
}
document.querySelector("#" + id).addEventListener('click', ()=>{
launchDocument(filePath);
})
});
}
function fileNameToPrettyString(fileName: string): string {
let name = fileName.substr(0, fileName.lastIndexOf('.'));
name = name.replace(/[.\-_]/ig, " ")
let buffer = name.split('');
for (let i = 0, l = buffer.length; i < l; i++) {
if (0 === i || ' ' === buffer[i - 1]) {
buffer[i] = buffer[i].toUpperCase()
}
}
return buffer.join('');
}
function getImagePathFromDocumentName(name: string): string {
return fu.getPathToImage(config.getFileExtensionToImageMap()[fu.getFileExtension(name)])
}
function launchDocument(filename) {
let fullPath = fu.getPathToDocument(filename);
shell.openItem(fullPath);
}
function launchWebsite(url) {
shell.openItem(url);
}
Loading…
Cancel
Save