Répercussion changement de noms entre classe et interface RemoteSource/RemoteSources.

This commit is contained in:
Fabrice PENHOËT 2021-10-13 17:22:02 +02:00
parent 879ef17fe2
commit 75c9179902
9 changed files with 37 additions and 45 deletions

View File

@ -6,7 +6,6 @@ const initialise = async () =>
{
// Création d'un convertisseur parsant des données transmises en HTML
let converter=new FreeDatas2HTML("HTML");
// converter.parser.setRemoteSource({ url: "http://localhost:8080/datas/posts.json", withCredentials:true, headers: [{ key:"Authorization", value:"Token YWxhZGRpbjpvcGVuc2VzYW1l" }] });
converter.datasViewElt={ id:"datas" };
await converter.run();
// Adaptation du rendu suivant la taille de l'écran

View File

@ -1,7 +1,7 @@
const { compare }=require('natural-orderby');
const errors=require("./errors.js");
import { Counter, Datas, DatasRenders, DOMElement, Paginations, Parsers, ParseErrors, RemoteSource, Selectors, SortingFields, SortingFunctions } from "./freeDatas2HTMLInterfaces";
import { Counter, Datas, DatasRenders, DOMElement, Paginations, Parsers, ParseErrors, RemoteSources, Selectors, SortingFields, SortingFunctions } from "./freeDatas2HTMLInterfaces";
import { Pagination} from "./freeDatas2HTMLPagination";
import { ParserForCSV} from "./freeDatas2HTMLParserForCSV";
import { ParserForHTML} from "./freeDatas2HTMLParserForHTML";
@ -20,12 +20,7 @@ export class FreeDatas2HTML
public datasHTML: string = "";
// Le parseur :
public parser: Parsers; // public pour permettre de charger un parseur tiers après instanciation
// Données distantes :
//private _datasRemoteSource: RemoteSource|undefined=undefined;
// Ou locales :
//private _datas2Parse:string|undefined=undefined;
// Dans tous les cas, besoin d'un type :
// Type de données à traiter
public datasType: "CSV"|"HTML"|"JSON"|undefined;
// Le nom des champs trouvés dans les données :
@ -53,7 +48,7 @@ export class FreeDatas2HTML
// J'initialiser avec des valeurs par défaut pouvant être surchargées par les setters
// Attention, si je transmets datasRemoteSource ici, il ne passera pas par un new RemoteSources()
// Il doit donc déjà avoir été testé
constructor(datasType:"CSV"|"HTML"|"JSON", datas2Parse="", datasRemoteSource?:RemoteSource)
constructor(datasType:"CSV"|"HTML"|"JSON", datas2Parse="", datasRemoteSource?:RemoteSources)
{
this.datasRender=new Render(this);
switch (datasType)

View File

@ -65,7 +65,7 @@ export interface ParseResults
}
export interface Parsers
{
datasRemoteSource: RemoteSource;
datasRemoteSource: RemoteSources;
setRemoteSource(settings : RemoteSourceSettings): void;
datas2Parse?: string;
document2Parse?: HTMLDocument;
@ -78,7 +78,7 @@ export interface RemoteSourceSettings
headers?: { key:string, value:string }[];
withCredentials?: boolean;
}
export interface RemoteSource extends RemoteSourceSettings
export interface RemoteSources extends RemoteSourceSettings
{
getFetchSettings() : {};
}

View File

@ -1,9 +1,12 @@
const Papa = require("papaparse");
const errors = require("./errors.js");
import { RemoteSources } from "./freeDatas2HTMLRemoteSources";
const Papa=require("papaparse");
const errors= require("./errors.js");
import { RemoteSource } from "./freeDatas2HTMLRemoteSource";
import { ParseResults, Parsers, RemoteSource, RemoteSourceSettings } from "./freeDatas2HTMLInterfaces";
interface PapaParseOptions
import { ParseResults, Parsers, RemoteSources, RemoteSourceSettings } from "./freeDatas2HTMLInterfaces";
// Options de Papa Parse
// cf. https://www.papaparse.com/docs#config
interface PublicPapaParseOptions
{
delimiter: string;
newline: string;
@ -11,28 +14,25 @@ interface PapaParseOptions
escapeChar: string;
transformHeader?(field: string, index: number): string;
preview: number;
comments: false|string,
comments: false|string;
fastMode: boolean|undefined;
transform?(value: string): string;
}
interface PrivatePapaParseOptions
{
header: boolean; // nécessaire pour obtenir le nom des champs
header: boolean;
download: boolean;
downloadRequestHeaders: undefined| { [index: string]:string|boolean|number } ;
downloadRequestHeaders: undefined| { [index: string]:string };
skipEmptyLines: string;
withCredentials: boolean|undefined;
}
export class ParserForCSV implements Parsers
{
private _datasRemoteSource: RemoteSource;
private _datasRemoteSource: RemoteSources;
private _datas2Parse:string="";
private _parseResults:ParseResults|undefined=undefined;
// Ouverture de certaines options de Papa Parse :
// cf. https://www.papaparse.com/docs#config
public options: PapaParseOptions =
public options: PublicPapaParseOptions =
{
delimiter: "",
newline: "",
@ -55,20 +55,20 @@ export class ParserForCSV implements Parsers
}
// L'instance d'une autre classe que RemoteSource peut être passée au constructeur
constructor(datasRemoteSource?: RemoteSource)
constructor(datasRemoteSource?: RemoteSources)
{
if(datasRemoteSource !== undefined)
this._datasRemoteSource=datasRemoteSource;
else
this._datasRemoteSource=new RemoteSources({ url:"" });
this._datasRemoteSource=new RemoteSource({ url:"" });
}
public setRemoteSource(source: RemoteSourceSettings)
{
this._datasRemoteSource=new RemoteSources(source);
this._datasRemoteSource=new RemoteSource(source);
}
get datasRemoteSource() : RemoteSource
get datasRemoteSource() : RemoteSources
{
return this._datasRemoteSource;
}

View File

@ -1,10 +1,10 @@
const errors=require("./errors.js");
import { ParseErrors, ParseResults, Parsers, RemoteSource, RemoteSourceSettings } from "./freeDatas2HTMLInterfaces";
import { RemoteSources } from "./freeDatas2HTMLRemoteSources";
import { ParseErrors, ParseResults, Parsers, RemoteSources, RemoteSourceSettings } from "./freeDatas2HTMLInterfaces";
import { RemoteSource } from "./freeDatas2HTMLRemoteSource";
export class ParserForHTML implements Parsers
{
private _datasRemoteSource: RemoteSource;
private _datasRemoteSource: RemoteSources;
private _document2Parse: HTMLDocument=document;
private _parseResults: ParseResults|undefined=undefined;
private _fieldsSelector: string="table > thead > tr > th";
@ -12,20 +12,20 @@ export class ParserForHTML implements Parsers
private _datasSelector: string="tr > td";
// L'instance d'une autre classe que RemoteSource peut être passée au constructeur
constructor(datasRemoteSource?: RemoteSource)
constructor(datasRemoteSource?: RemoteSources)
{
if(datasRemoteSource !== undefined)
this._datasRemoteSource=datasRemoteSource;
else
this._datasRemoteSource=new RemoteSources({ url:"" });
this._datasRemoteSource=new RemoteSource({ url:"" });
}
public setRemoteSource(source: RemoteSourceSettings)
{
this._datasRemoteSource=new RemoteSources(source);
this._datasRemoteSource=new RemoteSource(source);
}
get datasRemoteSource() : RemoteSource
get datasRemoteSource() : RemoteSources
{
return this._datasRemoteSource;
}

View File

@ -1,29 +1,29 @@
const errors = require("./errors.js");
import { RemoteSources } from "./freeDatas2HTMLRemoteSources";
import { RemoteSource } from "./freeDatas2HTMLRemoteSource";
import { ParseErrors, ParseResults, Parsers, RemoteSource, RemoteSourceSettings } from "./freeDatas2HTMLInterfaces";
import { ParseErrors, ParseResults, Parsers, RemoteSources, RemoteSourceSettings } from "./freeDatas2HTMLInterfaces";
export class ParserForJSON implements Parsers
{
private _datasRemoteSource: RemoteSource;
private _datasRemoteSource: RemoteSources;
private _datas2Parse: string="";
private _parseResults: ParseResults|undefined=undefined;
// L'instance d'une autre classe que RemoteSource peut être passée au constructeur
constructor(datasRemoteSource?: RemoteSource)
constructor(datasRemoteSource?: RemoteSources)
{
if(datasRemoteSource !== undefined)
this._datasRemoteSource=datasRemoteSource;
else
this._datasRemoteSource=new RemoteSources({ url:"" });
this._datasRemoteSource=new RemoteSource({ url:"" });
}
public setRemoteSource(source: RemoteSourceSettings)
{
this._datasRemoteSource=new RemoteSources(source);
this._datasRemoteSource=new RemoteSource(source);
}
get datasRemoteSource() : RemoteSource
get datasRemoteSource() : RemoteSources
{
return this._datasRemoteSource;
}

View File

@ -1,5 +1,5 @@
const Papa = require("papaparse");
import { RemoteSource, RemoteSourceSettings } from "../src/freeDatas2HTMLInterfaces";
import { RemoteSourceSettings } from "../src/freeDatas2HTMLInterfaces";
import { ParserForCSV as Parser } from "../src/freeDatas2HTMLParserForCSV";
const errors=require("../src/errors.js");

View File

@ -1,4 +1,3 @@
import { RemoteSource } from "../src/freeDatas2HTMLInterfaces";
import { ParserForHTML as Parser } from "../src/freeDatas2HTMLParserForHTML";
const errors=require("../src/errors.js");
const fixtures=require("./fixtures.js");

View File

@ -1,4 +1,3 @@
import { RemoteSource } from "../src/freeDatas2HTMLInterfaces";
import { ParserForJSON as Parser } from "../src/freeDatas2HTMLParserForJSON";
const errors=require("../src/errors.js");