-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #508 from datosgobar/504-actualizar-webcode
504 - Actualizar webcode de Components exportables
- Loading branch information
Showing
13 changed files
with
553 additions
and
208 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 2 additions & 5 deletions
7
src/components/common/linkBuilders.ts → src/helpers/card/cardLinkBuilders.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,11 @@ | ||
export function formatUrl(url: string, format: string): string { | ||
return `${url}&format=${format}` | ||
return `${url}&format=${format}`; | ||
} | ||
|
||
export function viewDatosGobAr(serieId: string, collapse?: string): string { | ||
|
||
const viewURL = `https://datos.gob.ar/series/api/series/?ids=${serieId}` | ||
const viewURL = `https://datos.gob.ar/series/api/series/?ids=${serieId}`; | ||
if (collapse === undefined) { | ||
return viewURL; | ||
} | ||
const finalURL = `${viewURL}&collapse=${collapse}`; | ||
return finalURL; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import { ISerie } from "../../api/Serie"; | ||
import { IWebSnippetOptions } from "../../components/exportable_card/FullCardDropdown"; | ||
import { cleanUrl } from "../graphic/graphicLinkBuilders"; | ||
|
||
export function cardWebCode(options: IWebSnippetOptions): string { | ||
|
||
let htmlScript = `<script type='text/javascript' src='https://cdn.jsdelivr.net/gh/datosgobar/series-tiempo-ar-explorer@ts_components_2.6.1/dist/js/components.js'></script> | ||
<link rel='stylesheet' type='text/css' href='https://cdn.jsdelivr.net/gh/datosgobar/series-tiempo-ar-explorer@ts_components_2.6.1/dist/css/components.css'/> | ||
<link type='text/css' rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.2/css/all.min.css' media='all' />" | ||
<div id="root"></div> | ||
<script> | ||
window.onload = function() { | ||
TSComponents.Card.render('root', { | ||
serieId: "${options.serieId}", | ||
color: "${options.color}", | ||
links: "${options.links}", | ||
hasChart: "${options.hasChart}"`; | ||
|
||
if(options.locale !== undefined) | ||
{ | ||
htmlScript += `, | ||
locale: "${options.locale}"`; | ||
} | ||
if(options.chartType !== undefined) | ||
{ | ||
htmlScript += `, | ||
chartType: "${options.chartType}"`; | ||
} | ||
if(options.explicitSign !== undefined) | ||
{ | ||
htmlScript += `, | ||
explicitSign: ${options.explicitSign}`; | ||
} | ||
if(options.title !== undefined) | ||
{ | ||
htmlScript += `, | ||
title: "${options.title}"`; | ||
} | ||
if(options.source !== undefined) | ||
{ | ||
htmlScript += `, | ||
source: "${options.source}"`; | ||
} | ||
if(options.units !== undefined) | ||
{ | ||
htmlScript += `, | ||
units: "${options.units}"`; | ||
} | ||
if(options.hasFrame !== undefined) | ||
{ | ||
htmlScript += `, | ||
hasFrame: ${options.hasFrame}`; | ||
} | ||
if(options.hasColorBar !== undefined) | ||
{ | ||
htmlScript += `, | ||
hasColorBar: ${options.hasColorBar}`; | ||
} | ||
if(options.collapse !== undefined) | ||
{ | ||
htmlScript += `, | ||
collapse: "${options.collapse}"`; | ||
} | ||
if(options.apiBaseUrl !== undefined) | ||
{ | ||
htmlScript += `, | ||
apiBaseUrl: "${options.apiBaseUrl}"`; | ||
} | ||
if(options.decimals !== undefined) | ||
{ | ||
htmlScript += `, | ||
decimals: ${options.decimals}`; | ||
} | ||
|
||
htmlScript += ` | ||
}) | ||
} | ||
</script> | ||
`; | ||
|
||
return htmlScript; | ||
} | ||
|
||
export function graphicWebCode(url: string, series: ISerie[]): string { | ||
|
||
const graphicUrl = cleanUrl(url); | ||
const title = calculateChartTitle(series); | ||
const source = calculateChartSource(series); | ||
const chartType = calculateChartType(url); | ||
|
||
let htmlScript = `<script type='text/javascript' src='https://cdn.jsdelivr.net/gh/datosgobar/series-tiempo-ar-explorer@ts_components_2.6.1/dist/js/components.js'></script> | ||
<link rel='stylesheet' type='text/css' href='https://cdn.jsdelivr.net/gh/datosgobar/series-tiempo-ar-explorer@ts_components_2.6.1/dist/css/components.css'/> | ||
<div id=\"root\"></div> | ||
<script> | ||
window.onload = function() { | ||
TSComponents.Graphic.render('root', { | ||
graphicUrl: "${graphicUrl}", | ||
title: "${title}", | ||
source: "${source}"`; | ||
|
||
if(chartType !== null && chartType !== "line") { | ||
htmlScript += `, | ||
chartType: "${chartType}"`; | ||
} | ||
|
||
htmlScript += ` | ||
}) | ||
} | ||
</script> | ||
`; | ||
|
||
return htmlScript; | ||
|
||
} | ||
|
||
export function calculateChartTitle(series: ISerie[]): string { | ||
return series.length > 1 ? series[0].datasetTitle : series[0].description; | ||
} | ||
|
||
export function calculateChartSource(series: ISerie[]): string { | ||
|
||
const sources = Array.from(new Set(series.map((serie: ISerie) => serie.datasetSource))); | ||
if(sources.length > 1) { | ||
const sourcesString = sources.join(', '); | ||
return `Fuentes: ${sourcesString}`; | ||
} | ||
return `Fuente: ${sources[0]}`; | ||
|
||
} | ||
|
||
export function calculateChartType(url: string): string | null { | ||
|
||
const params = url.split('?')[1]; | ||
const urlSearchParams = new URLSearchParams(params); | ||
return urlSearchParams.get('chartType'); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export function webShareURL(): string { | ||
return window.location.href; | ||
} | ||
export function urlToString(url: string): string { | ||
return url.replace(new RegExp('%2C', 'g'), ',') | ||
.replace(new RegExp('%3A', 'g'), ':') | ||
.replace(new RegExp('%2F', 'g'), '/') | ||
.replace(new RegExp('%3F', 'g'), '?'); | ||
} | ||
export function cleanUrl(url: string): string { | ||
const host = url.split('?')[0]; | ||
const params = url.split('?')[1]; | ||
const urlSearchParams = new URLSearchParams(params); | ||
urlSearchParams.delete('chartType'); | ||
return `${urlToString(`${host}?${urlSearchParams.toString()}`)}`; | ||
} | ||
export function csvShareURL(url: string): string { | ||
const host = url.split('?')[0]; | ||
const params = url.split('?')[1]; | ||
const urlSearchParams = new URLSearchParams(params); | ||
urlSearchParams.delete('metadata'); | ||
urlSearchParams.delete('start'); | ||
urlSearchParams.delete('chartType'); | ||
return `${urlToString(`${host}?${urlSearchParams.toString()}`)}&format=csv`; | ||
} | ||
export function jsonShareURL(url: string): string { | ||
return `${cleanUrl(url)}&format=json`; | ||
} |
Oops, something went wrong.