@ -1,37 +1,40 @@
import { Config urator, FileUtil s, ConfigPath s} from './fileutils'
import { Config Paths, Config urator, FileUtil s} from './fileutils'
import { loadTemplateSingle } from "./templates"
import { loadTemplateSingle } from "./templates"
import { WebUtils } from "./webutils"
const shell = require ( 'electron' ) . shell ;
const shell = require ( 'electron' ) . shell ;
export class CardModel {
export class CardModel {
imagePath : string ;
title : string ;
fileName : string ;
description : string ;
imgPath : string ;
constructor ( imagePath : string , name : string ) {
resourcePath : string ;
this . imagePath = imagePath ;
this . fileName = name ;
constructor ( title : string , description : string , imagePath : string , resourcePath : string ) {
this . title = title ;
this . description = description ;
this . imgPath = imagePath ;
this . resourcePath = resourcePath ;
}
}
}
}
export function buildFileCard ( filePath : string , elem : Element , append : boolean = false , $ : any = require ( 'jquery' ) ) {
export function buildFileCard ( filePath : string , elem : Element , append : boolean = false , $ : any = require ( 'jquery' ) ) {
let model = new CardModel ( getImagePathFromDocumentName ( filePath ) , fileNameToPrettyString ( filePath ) ) ;
// let model = new CardModel(getImagePathFromDocumentName(filePath), fileNameToPrettyString(filePath));
loadTemplateSingle ( "file-card.mustache" , model , ( content : string , id : string ) = > {
// loadTemplateSingle("file-card.mustache", model, (content: string, id: string) => {
let snip = $ ( content ) ;
// let snip = $(content);
let container = $ ( "#" + elem . id ) ;
// let container = $("#" + elem.id);
//
if ( append ) {
// if (append) {
container . append ( snip ) ;
// container.append(snip);
} else {
// } else {
container . empty ( ) . append ( snip ) ;
// container.empty().append(snip);
}
// }
setTimeout ( ( ) = > {
// setTimeout(() => {
$ ( ` # ${ id } ` ) . on ( "click" , ( ) = > {
// $(`#${id}`).on("click", () => {
launchDocument ( filePath ) ;
// launchDocument(filePath);
} ) ;
// });
} , 1 ) ; //for some reason we have to let the dom breathe before it will let us do this?
// }, 1); //for some reason we have to let the dom breathe before it will let us do this?
} ) ;
// });
}
}
export function buildDefaultWebCards ( elem : Element ) {
export function buildDefaultWebCards ( elem : Element ) {
@ -46,39 +49,25 @@ export function buildDefaultWebCards(elem: Element) {
export function buildWebCard ( urlText : string , elem : Element , append : boolean = false , $ : any = require ( 'jquery' ) ) {
export function buildWebCard ( urlText : string , elem : Element , append : boolean = false , $ : any = require ( 'jquery' ) ) {
let url = new URL ( urlText ) ;
let url = new URL ( urlText ) ;
let favicon = WebUtils . getFaviconUrl ( url ) ;
let model = new CardModel ( favicon , urlText ) ;
loadTemplateSingle ( "web-card.mustache" , model , ( content : string , id : string ) = > {
let model = new CardModel (
"Paycor" ,
"Clock in and out, request time off, review health benefits and access paystubs using the Paycor human-resources application." ,
FileUtils . getPathToImage ( "PaycorLogo2-Circle_100x100.png" ) ,
urlText
) ;
loadTemplateSingle ( "web-card.mustache" , model , ( content : string , id : string ) = > {
console . log ( content ) ;
if ( append ) {
if ( append ) {
elem . innerHTML = elem . innerHTML + content ;
elem . innerHTML = elem . innerHTML + content ;
} else {
} else {
elem . innerHTML = content ;
elem . innerHTML = content ;
}
}
new Promise < string > ( ( resolve , reject ) = > {
$ . get ( url . toString ( ) , ( data , status ) = > {
try {
if ( 'success' === status ) {
resolve ( $ ( data ) . filter ( 'title' ) . text ( ) ) ;
}
} catch ( a ) {
console . error ( "Error while attempting to fetch page title" , a )
}
} ) . fail ( ( failure ) = > {
reject ( failure ) ;
} )
} ) . then ( ( value : string ) = > {
let stubb = $ ( ` # ${ id } -title ` ) . html ( $ ( "<p>" , { class : "pr-3 mb-0" } ) ) ;
stubb . html ( value ) ;
$ ( ` # ${ id } ` ) . on ( "click" , ( ) = > {
$ ( ` # ${ id } ` ) . on ( "click" , ( ) = > {
launchWebsite ( url . toString ( ) ) ;
launchWebsite ( url . toString ( ) ) ;
} ) ;
} ) ;
} ) . catch ( reason = > {
let card = $ ( "<p>" , { id : "come on" , class : "pr-3 mb-0" } ) ;
card . text ( urlText ) ;
$ ( ` # ${ id } -title ` ) . html ( card ) ;
} ) ;
} ) ;
} ) ;
}
}