<commit_before>/**
 * This file is part of the MonVoisinFaitDuBio project.
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright Copyright (c) 2016 <NAME> - <EMAIL>
 * @license    MIT License
 * @Last Modified time: 2016-12-13
 */
import { AppModule, AppStates } from "../app.module";
import { BiopenMarker } from "../components/map/biopen-marker.component";

declare let App : AppModule;
declare var $;
declare let Twig : any;
declare let twigJs_elementInfo : any;

export class Element 
{	
	readonly id : number;
	readonly name : string;
	readonly position : L.LatLng;
	readonly address : string;
	readonly description : string;
	readonly tel : string;
	readonly webSite : string;
	readonly mail : string;
	readonly products : any[] = [];

	//TODO
	mainProduct : any;
	mainProductIsDisabled : boolean;
	horaires : any;
	type : any;	

	distance : number;

	isInitialized_ :boolean = false;

	isVisible_ : boolean = false;
	isInElementList : boolean= false;

	//TODO
	biopenMarker_ : BiopenMarker = null;
	htmlRepresentation_ = '';
	formatedHoraire_ : any = null;

	productsToDisplay_ : any = {};

	starChoiceForRepresentation = '';
	isShownAlone : boolean= false;

	isFavorite : boolean= false;

	constructor(elementJson : any)
	{
		this.id = elementJson.id;
		this.name = elementJson.name;
		this.position = L.latLng(elementJson.latlng.latitude, elementJson.latlng.longitude);
		this.address = elementJson.adresse;
		this.description = elementJson.description;
		this.tel = elementJson.tel ? elementJson.tel.replace(/(.{2})(?!$)/g,"$1 ") : '';	
		this.webSite = elementJson.web_site;
		this.mail = elementJson.mail;

		this.products = [];
		let product;
		if (elementJson.type == 'epicerie') 
		{
			product = [];

			product.name = 'Epicerie';
			product.nameShort = 'Epicerie';
			product.nameFormate = 'epicerie';

			this.products.push(product);
		}
		else
		{
			for (let i = 0; i < elementJson.products.length; i++) 
			{
				product = [];

				product.name = elementJson.products[i].product.name;
				product.nameShort = elementJson.products[i].product.name_short;
				product.nameFormate = elementJson.products[i].product.name_formate;
				product.descriptif = elementJson.products[i].descriptif;
				product.disabled = false;

				this.products.push(product);
			}
		}

		this.mainProduct = elementJson.main_product;
		this.mainProductIsDisabled = false;
		this.horaires = elementJson.horaires;
		this.type = elementJson.type;	

		this.distance = elementJson.distance ? Math.round(elementJson.distance) : null;
	}

initialize() 
{		
	if (!this.isInitialized_) 
	{
		this.biopenMarker_ = new BiopenMarker(this.id, this.position);
		this.isInitialized_ = true;
	}		
}

show() 
{		
	if (!this.isInitialized_) this.initialize();	
	//this.biopenMarker_.updateIcon();
	this.biopenMarker_.show();
	this.isVisible_ = true;		
};

hide() 
{		
	if (this.biopenMarker_) this.biopenMarker_.hide();
	this.isVisible_ = false;
	// unbound events (click etc...)?
	//if (constellationMode) $('#ElementList #element-info-'+this.id).hide();
};



updateProductsRepresentation() 
{		
	if (App.state !== AppStates.Constellation) return;

	// let starNames = App.constellation.getStarNamesRepresentedByElementId(this.id);
	// if (this.isProducteurOrAmap())
	// {
	// 	for(let i = 0; i < this.products.length;i++)
	// 	{
	// 		productName = this.products[i].nameFormate;			

	// 		if ($.inArray(productName, starNames) == -1)
	// 		{
	// 			this.products[i].disabled = true;				
	// 			if (productName == this.mainProduct) this.mainProductIsDisabled = true;				
	// 		}	
	// 		else
	// 		{
	// 			this.products[i].disabled = false;				
	// 			if (productName == this.mainProduct) this.mainProductIsDisabled = false;		
	// 		}		
	// 	}
	// }
	// else
	// {
	// 	if (starNames.length === 0) this.mainProductIsDisabled = true;	
	// 	else this.mainProductIsDisabled = false;	
	// }
};

getHtmlRepresentation() 
{	
	//let starNames = App.state == AppStates.Constellation ? App.constellation.getStarNamesRepresentedByElementId(this.id) : [];
	let starNames : any[] = [] ;

	this.distance = App.mapComponent.distanceFromLocationTo(this.position);
	// distance vol d'oiseau, on arrondi et on l'augmente un peu
	this.distance = Math.round(1.2*this.distance);


	let html = Twig.render(twigJs_elementInfo, 
				{
					element : this, 
					horaires : this.getFormatedHoraires(), 
					constellationMode: App.state == AppStates.Constellation, 
					productsToDisplay: this.getProductsNameToDisplay(), 
					starNames : starNames 
				});
	this.htmlRepresentation_ = html;				
	return html;
};

getProductsNameToDisplay()
{<commit_msg>Change twig_js alias<commit_after>/**
 * This file is part of the MonVoisinFaitDuBio project.
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright Copyright (c) 2016 <NAME> - <EMAIL>
 * @license    MIT License
 * @Last Modified time: 2016-12-13
 */
import { AppModule, AppStates } from "../app.module";
import { BiopenMarker } from "../components/map/biopen-marker.component";

declare let App : AppModule;
declare var $;
declare let Twig : any;
declare let biopen_twigJs_elementInfo : any;

export class Element 
{	
	readonly id : number;
	readonly name : string;
	readonly position : L.LatLng;
	readonly address : string;
	readonly description : string;
	readonly tel : string;
	readonly webSite : string;
	readonly mail : string;
	readonly products : any[] = [];

	//TODO
	mainProduct : any;
	mainProductIsDisabled : boolean;
	horaires : any;
	type : any;	

	distance : number;

	isInitialized_ :boolean = false;

	isVisible_ : boolean = false;
	isInElementList : boolean= false;

	//TODO
	biopenMarker_ : BiopenMarker = null;
	htmlRepresentation_ = '';
	formatedHoraire_ : any = null;

	productsToDisplay_ : any = {};

	starChoiceForRepresentation = '';
	isShownAlone : boolean= false;

	isFavorite : boolean= false;

	constructor(elementJson : any)
	{
		this.id = elementJson.id;
		this.name = elementJson.name;
		this.position = L.latLng(elementJson.latlng.latitude, elementJson.latlng.longitude);
		this.address = elementJson.adresse;
		this.description = elementJson.description;
		this.tel = elementJson.tel ? elementJson.tel.replace(/(.{2})(?!$)/g,"$1 ") : '';	
		this.webSite = elementJson.web_site;
		this.mail = elementJson.mail;

		this.products = [];
		let product;
		if (elementJson.type == 'epicerie') 
		{
			product = [];

			product.name = 'Epicerie';
			product.nameShort = 'Epicerie';
			product.nameFormate = 'epicerie';

			this.products.push(product);
		}
		else
		{
			for (let i = 0; i < elementJson.products.length; i++) 
			{
				product = [];

				product.name = elementJson.products[i].product.name;
				product.nameShort = elementJson.products[i].product.name_short;
				product.nameFormate = elementJson.products[i].product.name_formate;
				product.descriptif = elementJson.products[i].descriptif;
				product.disabled = false;

				this.products.push(product);
			}
		}

		this.mainProduct = elementJson.main_product;
		this.mainProductIsDisabled = false;
		this.horaires = elementJson.horaires;
		this.type = elementJson.type;	

		this.distance = elementJson.distance ? Math.round(elementJson.distance) : null;
	}

initialize() 
{		
	if (!this.isInitialized_) 
	{
		this.biopenMarker_ = new BiopenMarker(this.id, this.position);
		this.isInitialized_ = true;
	}		
}

show() 
{		
	if (!this.isInitialized_) this.initialize();	
	//this.biopenMarker_.updateIcon();
	this.biopenMarker_.show();
	this.isVisible_ = true;		
};

hide() 
{		
	if (this.biopenMarker_) this.biopenMarker_.hide();
	this.isVisible_ = false;
	// unbound events (click etc...)?
	//if (constellationMode) $('#ElementList #element-info-'+this.id).hide();
};



updateProductsRepresentation() 
{		
	if (App.state !== AppStates.Constellation) return;

	// let starNames = App.constellation.getStarNamesRepresentedByElementId(this.id);
	// if (this.isProducteurOrAmap())
	// {
	// 	for(let i = 0; i < this.products.length;i++)
	// 	{
	// 		productName = this.products[i].nameFormate;			

	// 		if ($.inArray(productName, starNames) == -1)
	// 		{
	// 			this.products[i].disabled = true;				
	// 			if (productName == this.mainProduct) this.mainProductIsDisabled = true;				
	// 		}	
	// 		else
	// 		{
	// 			this.products[i].disabled = false;				
	// 			if (productName == this.mainProduct) this.mainProductIsDisabled = false;		
	// 		}		
	// 	}
	// }
	// else
	// {
	// 	if (starNames.length === 0) this.mainProductIsDisabled = true;	
	// 	else this.mainProductIsDisabled = false;	
	// }
};

getHtmlRepresentation() 
{	
	//let starNames = App.state == AppStates.Constellation ? App.constellation.getStarNamesRepresentedByElementId(this.id) : [];
	let starNames : any[] = [] ;

	this.distance = App.mapComponent.distanceFromLocationTo(this.position);
	// distance vol d'oiseau, on arrondi et on l'augmente un peu
	this.distance = Math.round(1.2*this.distance);


	let html = Twig.render(biopen_twigJs_elementInfo, 
	{
		element : this, 
		horaires : this.getFormatedHoraires(), 
		constellationMode: App.state == AppStates.Constellation, 
		productsToDisplay: this.getProductsNameToDisplay(), 
		starNames : starNames 
	});
	
	this.htmlRepresentation_ = html;				
	return html;
};

getProductsNameToDisplay()
{
{'fraction_non_alphanumeric': 0.1376302914273559, 'fraction_numerical': 0.0042544139544777706, 'mean_word_length': 3.5645631067961165, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2646461', 'n_tokens_mistral': 3523, 'n_tokens_neox': 3167, 'n_words': 632}