explore-services/sample-components/sampleComponent-2/src/app/home/home.component.ts

109 lines
42 KiB
TypeScript
Raw Normal View History

import {Component} from '@angular/core';
import {Router} from '@angular/router';
import {Observable} from 'rxjs/Observable';
import {Location} from '@angular/common';
declare var Cite:CiteType;
declare var fs:any;
declare var module:any;
declare var child_process:any;
declare var simpleSys:Function;
interface CiteType {
set:Function;
get:Function;
setOptions:Function;
}
@Component({
selector: 'home',
templateUrl: 'home.component.html',
})
export class HomeComponent {
styles:string[]=["bibtex","chicago","ieee","science","apa","cell","harvard","mla","nature","acm"];
selectedStyle:string = "bibtex";
citation:string="";
constructor ( private _router: Router, private location: Location) {
// var fs = require('fs');
// if(typeof document !== undefined) {
// var citeproc = require("citeproc-js-node");
//
// var sys = citeproc.simpleSys();
// // Wherever your locale and style files are. None are included with the package.
// var enUS = '<?xml version="1.0" encoding="utf-8"?> <locale xmlns="http://purl.org/net/xbiblio/csl" version="1.0" xml:lang="en-US"> <info> <rights license="http://creativecommons.org/licenses/by-sa/3.0/">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights> <updated>2015-10-10T23:31:02+00:00</updated> </info> <style-options punctuation-in-quote="true"/> <date form="text"> <date-part name="month" suffix=" "/> <date-part name="day" suffix=", "/> <date-part name="year"/> </date> <date form="numeric"> <date-part name="month" form="numeric-leading-zeros" suffix="/"/> <date-part name="day" form="numeric-leading-zeros" suffix="/"/> <date-part name="year"/> </date> <terms> <term name="accessed">accessed</term> <term name="and">and</term> <term name="and others">and others</term> <term name="anonymous">anonymous</term> <term name="anonymous" form="short">anon.</term> <term name="at">at</term> <term name="available at">available at</term> <term name="by">by</term> <term name="circa">circa</term> <term name="circa" form="short">c.</term> <term name="cited">cited</term> <term name="edition"> <single>edition</single> <multiple>editions</multiple> </term> <term name="edition" form="short">ed.</term> <term name="et-al">et al.</term> <term name="forthcoming">forthcoming</term> <term name="from">from</term> <term name="ibid">ibid.</term> <term name="in">in</term> <term name="in press">in press</term> <term name="internet">internet</term> <term name="interview">interview</term> <term name="letter">letter</term> <term name="no date">no date</term> <term name="no date" form="short">n.d.</term> <term name="online">online</term> <term name="presented at">presented at the</term> <term name="reference"> <single>reference</single> <multiple>references</multiple> </term> <term name="reference" form="short"> <single>ref.</single> <multiple>refs.</multiple> </term> <term name="retrieved">retrieved</term> <term name="scale">scale</term> <term name="version">version</term> <!-- ANNO DOMINI; BEFORE CHRIST --> <term name="ad">AD</term> <term name="bc">BC</term> <!-- PUNCTUATION --> <term name="open-quote">“</term> <term name="close-quote">”</term> <term name="open-inner-quote"></term> <term name="close-inner-quote"></term> <term name="page-range-delimiter"></term> <!-- ORDINALS --> <term name="ordinal">th</term> <term name="ordinal-01">st</term> <term name="ordinal-02">nd</term> <term name="ordinal-03">rd</term> <term name="ordinal-11">th</term> <term name="ordinal-12">th</term> <term name="ordinal-13">th</term> <!-- LONG ORDINALS --> <term name="long-ordinal-01">first</term> <term name="long-ordinal-02">second</term> <term name="long-ordinal-03">third</term> <term name="long-ordinal-04">fourth</term> <term name="long-ordinal-05">fifth</term> <term name="long-ordinal-06">sixth</term> <term name="long-ordinal-07">seventh</term> <term name="long-ordinal-08">eighth</term> <term name="long-ordinal-09">ninth</term> <term name="long-ordinal-10">tenth</term> <!-- LONG LOCATOR FORMS --> <term name="book"> <single>book</single> <multiple>books</multiple> </term> <term name="chapter"> <single>chapter</single> <multiple>chapters</multiple> </term> <term name="column"> <single>column</single> <multiple>columns</multiple> </term> <term name="figure"> <single>figure</single> <multiple>figures</multiple> </term> <term name="folio"> <single>folio</single> <multiple>folios</multiple> </term> <term name="issue"> <single>number</single> <multiple>numbers</multiple> </term> <term name="line"> <single>line</single> <multiple>lines</multiple> </term> <term name="note"> <single>note</single> <multiple>notes</multiple> </term> <term name="opus"> <single>opus</single> <multiple>opera</multiple> </term> <term name="page"> <single>page</single> <multiple>pages</multiple> </term> <term name="number-of-pages"> <single>page</single> <multiple>pages</multiple> </term> <term name="paragraph"> <single>paragraph</single> <multiple>paragraphs</multiple> </term> <term name="part"> <single>part</single> <multiple>parts</multiple> </
// sys.addLocale('en-US', enUS);
// var styleString = '<?xml version="1.0" encoding="utf-8"?> <style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" demote-non-dropping-particle="sort-only" default-locale="en-US"> <info> <title>BibTeX generic citation style</title> <id>http://www.zotero.org/styles/bibtex</id> <link href="http://www.zotero.org/styles/bibtex" rel="self"/> <link href="http://www.bibtex.org/" rel="documentation"/> <author> <name>Markus Schaffner</name> </author> <contributor> <name>Richard Karnesky</name> <email>karnesky+zotero@gmail.com</email> <uri>http://arc.nucapt.northwestern.edu/Richard_Karnesky</uri> </contributor> <category citation-format="author-date"/> <category field="generic-base"/> <updated>2012-09-14T21:22:32+00:00</updated> <rights license="http://creativecommons.org/licenses/by-sa/3.0/">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights> </info> <macro name="zotero2bibtexType"> <choose> <if type="bill book graphic legal_case legislation motion_picture report song" match="any"> <text value="book"/> </if> <else-if type="chapter paper-conference" match="any"> <text value="inbook"/> </else-if> <else-if type="article article-journal article-magazine article-newspaper" match="any"> <text value="article"/> </else-if> <else-if type="thesis" match="any"> <text value="phdthesis"/> </else-if> <else-if type="manuscript" match="any"> <text value="unpublished"/> </else-if> <else-if type="paper-conference" match="any"> <text value="inproceedings"/> </else-if> <else-if type="report" match="any"> <text value="techreport"/> </else-if> <else> <text value="misc"/> </else> </choose> </macro> <macro name="citeKey"> <group delimiter="_"> <text macro="author-short" text-case="lowercase"/> <text macro="issued-year"/> </group> </macro> <macro name="author-short"> <names variable="author"> <name form="short" delimiter="_" delimiter-precedes-last="always"/> <substitute> <names variable="editor"/> <names variable="translator"/> <choose> <if type="bill book graphic legal_case legislation motion_picture report song" match="any"> <text variable="title" form="short"/> </if> <else> <text variable="title" form="short"/> </else> </choose> </substitute> </names> </macro> <macro name="issued-year"> <date variable="issued"> <date-part name="year"/> </date> </macro> <macro name="issued-month"> <date variable="issued"> <date-part name="month" form="short" strip-periods="true"/> </date> </macro> <macro name="author"> <names variable="author"> <name sort-separator=", " delimiter=" and " delimiter-precedes-last="always" name-as-sort-order="all"/> <label form="long" text-case="capitalize-first"/> </names> </macro> <macro name="editor-translator"> <names variable="editor translator" delimiter=", "> <name sort-separator=", " delimiter=" and " delimiter-precedes-last="always" name-as-sort-order="all"/> <label form="long" text-case="capitalize-first"/> </names> </macro> <macro name="title"> <text variable="title"/> </macro> <macro name="number"> <text variable="issue"/> <text variable="number"/> </macro> <macro name="container-title"> <choose> <if type="chapter paper-conference" match="any"> <text variable="container-title" prefix=" booktitle={" suffix="}"/> </if> <else> <text variable="container-title" prefix=" journal={" suffix="}"/> </else> </choose> </macro> <macro name="publisher"> <choose> <if type="thesis"> <text variable="publisher" prefix=" school={" suffix="}"/> </if> <else-if type="report"> <text variable="publisher" prefix=" institution={" suffix="}"/> </else-if> <else> <text variable="publisher" prefix=" publisher={" suffix="}"/> </else> </choose> </macro> <macro name="pages"> <text variable="page"/> </macro> <macro name="edition"> <text variable="edition"/> </macro> <citation et-al-min="10" et-al-use-first="10" disambiguate-add-year-suffix="true" disambiguate-add-names="false" disambiguate-add-givenname="false" collapse="year"> <sort> <key macro="author"/> <key variable="issued"/> </sort> <layout delimiter="_"> <text macro="citeKey"/> </layout> </citation> <bibliography hanging-indent="false"
// var engine = sys.newEngine(styleString, 'en-US', null);
//
// var items = {"14058/RN9M5BF3":{"accessed":{"month":"9","year":"2010","day":"10"},"id":"14058/RN9M5BF3","author":[{"given":"Adel","family":"Hendaoui"},{"given":"Moez","family":"Limayem"},{"given":"Craig W.","family":"Thompson"}],"title":"3D Social Virtual Worlds: <i>Research Issues and Challenges</i>","type":"article-journal","versionNumber":6816},"14058/NSBERGDK":{"accessed":{"month":"9","year":"2010","day":"10"},"issued":{"month":"6","year":"2009"},"event-place":"Istanbul","type":"paper-conference","DOI":"10.1109/DEST.2009.5276761","page-first":"151","id":"14058/NSBERGDK","title-short":"3D virtual worlds as collaborative communities enriching human endeavours","publisher-place":"Istanbul","author":[{"given":"C.","family":"Dreher"},{"given":"T.","family":"Reiners"},{"given":"N.","family":"Dreher"},{"given":"H.","family":"Dreher"}],"title":"3D virtual worlds as collaborative communities enriching human endeavours: Innovative applications in e-Learning","shortTitle":"3D virtual worlds as collaborative communities enriching human endeavours","page":"151-156","event":"2009 3rd IEEE International Conference on Digital Ecosystems and Technologies (DEST)","URL":"http://ieeexplore.ieee.org/lpdocs/epic03/wrapper.htm?arnumber=5276761","versionNumber":1}};
//
// sys.items = items;
//
// var clusters = [
// {
// citationItems: ["14058/RN9M5BF3"],
// properties: {
// note:0
// }
// },
// {
// citationItems: ["14058/NSBERGDK"],
// properties: {
// note:0
// }
// },
// ];
//
// engine.updateItems(Object.keys(items));
// var bib = engine.makeBibliography();
// console.log(bib[1]);
// this.citation =bib[1];
// }
var data= '[ { "id": "Q23571040", "type": "article-journal", "title": "Correlation of the Base Strengths of Amines 1", "DOI": "10.1021/ja01577a030", "author": [ { "given": "H. K.", "family": "Hall" } ], "issued": [ { "date-parts": [ "1957", "1", "1" ] } ], "container-title": "Journal of the American Chemical Society", "volume": "79", "issue": "20", "page": "5441-5444" } ]';
var Cite = require('../home/citation-0.2.js');
var opt = {
format: 'string',
type : 'string',
style : 'citation-apa',
lang : 'en-US'
};
// var Cite = require('citation-js');
var cite = new Cite(data, opt);
console.log("APA:"+cite.get());
opt = {
format: 'string',
type : 'string',
style : 'citation-harvard1',
lang : 'en-US'
};
cite = new Cite(data, opt);
// cite.set(data);
console.log("harvard1: "+cite.get());
var opt_template = {
format: 'string',
type : 'string',
style : 'citation-ieee',
lang : 'en-US',
template : '<?xml version="1.0" encoding="utf-8"?> <style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" demote-non-dropping-particle="sort-only"> <info> <title>IEEE (with URL)</title> <id>http://www.zotero.org/styles/ieee-with-url</id> <link href="http://www.zotero.org/styles/ieee-with-url" rel="self"/> <link href="http://www.ieee.org/documents/style_manual.pdf" rel="documentation"/> <link href="http://www.ieee.org/documents/auinfo07.pdf" rel="documentation"/> <author> <name>Michael Berkowitz</name> <email>mberkowi@gmu.edu</email> </author> <contributor> <name>Julian Onions</name> <email>julian.onions@gmail.com</email> </contributor> <contributor> <name>Rintze Zelle</name> <uri>http://twitter.com/rintzezelle</uri> </contributor> <contributor> <name>Stephen Frank</name> <uri>http://www.zotero.org/sfrank</uri> </contributor> <contributor> <name>Sebastian Karcher</name> </contributor> <category citation-format="numeric"/> <category field="engineering"/> <category field="generic-base"/> <updated>2012-10-18T22:38:43+00:00</updated> <rights license="http://creativecommons.org/licenses/by-sa/3.0/">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights> </info> <locale xml:lang="en"> <terms> <term name="chapter" form="short">ch.</term> <term name="presented at">presented at the</term> <term name="available at">available</term> </terms> </locale> <!-- Macros --> <macro name="edition"> <choose> <if type="bill book chapter graphic legal_case legislation motion_picture paper-conference report song" match="any"> <choose> <if is-numeric="edition"> <group delimiter=" "> <number variable="edition" form="ordinal"/> <text term="edition" form="short"/> </group> </if> <else> <text variable="edition" text-case="capitalize-first" suffix="."/> </else> </choose> </if> </choose> </macro> <macro name="issued"> <choose> <if type="article-journal report" match="any"> <date variable="issued"> <date-part name="month" form="short" suffix=" "/> <date-part name="year" form="long"/> </date> </if> <else-if type=" bill book chapter graphic legal_case legislation motion_picture paper-conference song thesis" match="any"> <date variable="issued"> <date-part name="year" form="long"/> </date> </else-if> <else> <date variable="issued"> <date-part name="day" form="numeric-leading-zeros" suffix="-"/> <date-part name="month" form="short" suffix="-" strip-periods="true"/> <date-part name="year" form="long"/> </date> </else> </choose> </macro> <macro name="author"> <names variable="author"> <name initialize-with=". " delimiter=", " and="text"/> <label form="short" prefix=", " text-case="capitalize-first"/> <substitute> <names variable="editor"/> <names variable="translator"/> </substitute> </names> </macro> <macro name="editor"> <names variable="editor"> <name initialize-with=". " delimiter=", " and="text"/> <label form="short" prefix=", " text-case="capitalize-first"/> </names> </macro> <macro name="locators"> <group delimiter=", "> <text macro="edition"/> <group delimiter=" "> <text term="volume" form="short"/> <number variable="volume" form="numeric"/> </group> <group delimiter=" "> <number variable="number-of-volumes" form="numeric"/> <text term="volume" form="short" plural="true"/> </group> <group delimiter=" "> <text term="issue" form="short"/> <number variable="issue" form="numeric"/> </group> </group> </macro> <macro name="title"> <choose> <if type="bill book graphic legal_case legislation motion_picture song" match="any"> <text variable="title" font-style="italic"/> </if> <else> <text variable="title" quotes="true"/> </else> </choose> </macro> <macro name="publisher"> <choose> <if type=" bill book chapter graphic legal_case legislation motion_picture paper-conference song" match="any"> <group delimiter=": "> <text variable="publisher-place"/> <text variable="publisher"/> </group> </if> <else> <group delimiter=", "> <text variable="publisher"/> <text variable="publisher-place"/> </group> </else> </choose> </macro> <macro name="event"> <choose> <if type="paper-conference speech" match="any"> <ch
};
// var opt = { format: 'string', type : 'string', style : 'citation-<NAME>', lang : 'en-US', template : <XML_CSL> };
var cite_template = new Cite(data, opt_template);
cite_template.set(data);
console.log("IEEE: "+cite_template.get());
}
bibtex:string =`<?xml version="1.0" encoding="utf-8"?> <style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" demote-non-dropping-particle="sort-only" default-locale="en-US"> <info> <title>BibTeX generic citation style</title> <id>http://www.zotero.org/styles/bibtex</id> <link href="http://www.zotero.org/styles/bibtex" rel="self"/> <link href="http://www.bibtex.org/" rel="documentation"/> <author> <name>Markus Schaffner</name> </author> <contributor> <name>Richard Karnesky</name> <email>karnesky+zotero@gmail.com</email> <uri>http://arc.nucapt.northwestern.edu/Richard_Karnesky</uri> </contributor> <category citation-format="author-date"/> <category field="generic-base"/> <updated>2012-09-14T21:22:32+00:00</updated> <rights license="http://creativecommons.org/licenses/by-sa/3.0/">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights> </info> <macro name="zotero2bibtexType"> <choose> <if type="bill book graphic legal_case legislation motion_picture report song" match="any"> <text value="book"/> </if> <else-if type="chapter paper-conference" match="any"> <text value="inbook"/> </else-if> <else-if type="article article-journal article-magazine article-newspaper" match="any"> <text value="article"/> </else-if> <else-if type="thesis" match="any"> <text value="phdthesis"/> </else-if> <else-if type="manuscript" match="any"> <text value="unpublished"/> </else-if> <else-if type="paper-conference" match="any"> <text value="inproceedings"/> </else-if> <else-if type="report" match="any"> <text value="techreport"/> </else-if> <else> <text value="misc"/> </else> </choose> </macro> <macro name="citeKey"> <group delimiter="_"> <text macro="author-short" text-case="lowercase"/> <text macro="issued-year"/> </group> </macro> <macro name="author-short"> <names variable="author"> <name form="short" delimiter="_" delimiter-precedes-last="always"/> <substitute> <names variable="editor"/> <names variable="translator"/> <choose> <if type="bill book graphic legal_case legislation motion_picture report song" match="any"> <text variable="title" form="short"/> </if> <else> <text variable="title" form="short"/> </else> </choose> </substitute> </names> </macro> <macro name="issued-year"> <date variable="issued"> <date-part name="year"/> </date> </macro> <macro name="issued-month"> <date variable="issued"> <date-part name="month" form="short" strip-periods="true"/> </date> </macro> <macro name="author"> <names variable="author"> <name sort-separator=", " delimiter=" and " delimiter-precedes-last="always" name-as-sort-order="all"/> <label form="long" text-case="capitalize-first"/> </names> </macro> <macro name="editor-translator"> <names variable="editor translator" delimiter=", "> <name sort-separator=", " delimiter=" and " delimiter-precedes-last="always" name-as-sort-order="all"/> <label form="long" text-case="capitalize-first"/> </names> </macro> <macro name="title"> <text variable="title"/> </macro> <macro name="number"> <text variable="issue"/> <text variable="number"/> </macro> <macro name="container-title"> <choose> <if type="chapter paper-conference" match="any"> <text variable="container-title" prefix=" booktitle={" suffix="}"/> </if> <else> <text variable="container-title" prefix=" journal={" suffix="}"/> </else> </choose> </macro> <macro name="publisher"> <choose> <if type="thesis"> <text variable="publisher" prefix=" school={" suffix="}"/> </if> <else-if type="report"> <text variable="publisher" prefix=" institution={" suffix="}"/> </else-if> <else> <text variable="publisher" prefix=" publisher={" suffix="}"/> </else> </choose> </macro> <macro name="pages"> <text variable="page"/> </macro> <macro name="edition"> <text variable="edition"/> </macro> <citation et-al-min="10" et-al-use-first="10" disambiguate-add-year-suffix="true" disambiguate-add-names="false" disambiguate-add-givenname="false" collapse="year"> <sort> <key macro="author"/> <key variable="issued"/> </sort> <layout delimiter="_"> <text macro="citeKey"/> </layout> </citation> <bibliography hanging-indent="false" et-al-min
ieee_csl:string =`<?xml version="1.0" encoding="utf-8"?> <style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" demote-non-dropping-particle="sort-only"> <info> <title>IEEE</title> <id>http://www.zotero.org/styles/ieee</id> <link href="http://www.zotero.org/styles/ieee" rel="self"/> <link href="http://www.ieee.org/documents/style_manual.pdf" rel="documentation"/> <link href="http://www.ieee.org/documents/auinfo07.pdf" rel="documentation"/> <author> <name>Michael Berkowitz</name> <email>mberkowi@gmu.edu</email> </author> <contributor> <name>Julian Onions</name> <email>julian.onions@gmail.com</email> </contributor> <contributor> <name>Rintze Zelle</name> <uri>http://twitter.com/rintzezelle</uri> </contributor> <contributor> <name>Stephen Frank</name> <uri>http://www.zotero.org/sfrank</uri> </contributor> <contributor> <name>Sebastian Karcher</name> </contributor> <category citation-format="numeric"/> <category field="engineering"/> <category field="generic-base"/> <updated>2016-10-06T15:32:30+00:00</updated> <rights license="http://creativecommons.org/licenses/by-sa/3.0/">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights> </info> <locale xml:lang="en"> <terms> <term name="chapter" form="short">ch.</term> <term name="presented at">presented at the</term> <term name="available at">available</term> </terms> </locale> <!-- Macros --> <macro name="edition"> <choose> <if type="bill book chapter graphic legal_case legislation motion_picture paper-conference report song" match="any"> <choose> <if is-numeric="edition"> <group delimiter=" "> <number variable="edition" form="ordinal"/> <text term="edition" form="short"/> </group> </if> <else> <text variable="edition" text-case="capitalize-first" suffix="."/> </else> </choose> </if> </choose> </macro> <macro name="issued"> <choose> <if type="article-journal report" match="any"> <date variable="issued"> <date-part name="month" form="short" suffix=" "/> <date-part name="year" form="long"/> </date> </if> <else-if type=" bill book chapter graphic legal_case legislation motion_picture paper-conference song thesis" match="any"> <date variable="issued"> <date-part name="year" form="long"/> </date> </else-if> <else> <date variable="issued"> <date-part name="day" form="numeric-leading-zeros" suffix="-"/> <date-part name="month" form="short" suffix="-" strip-periods="true"/> <date-part name="year" form="long"/> </date> </else> </choose> </macro> <macro name="author"> <names variable="author"> <name and="text" et-al-min="7" et-al-use-first="1" initialize-with=". "/> <label form="short" prefix=", " text-case="capitalize-first"/> <et-al font-style="italic"/> <substitute> <names variable="editor"/> <names variable="translator"/> </substitute> </names> </macro> <macro name="editor"> <names variable="editor"> <name initialize-with=". " delimiter=", " and="text"/> <label form="short" prefix=", " text-case="capitalize-first"/> </names> </macro> <macro name="locators"> <group delimiter=", "> <text macro="edition"/> <group delimiter=" "> <text term="volume" form="short"/> <number variable="volume" form="numeric"/> </group> <group delimiter=" "> <number variable="number-of-volumes" form="numeric"/> <text term="volume" form="short" plural="true"/> </group> <group delimiter=" "> <text term="issue" form="short"/> <number variable="issue" form="numeric"/> </group> </group> </macro> <macro name="title"> <choose> <if type="bill book graphic legal_case legislation motion_picture song" match="any"> <text variable="title" font-style="italic"/> </if> <else> <text variable="title" quotes="true"/> </else> </choose> </macro> <macro name="publisher"> <choose> <if type=" bill book chapter graphic legal_case legislation motion_picture paper-conference song" match="any"> <group delimiter=": "> <text variable="publisher-place"/> <text variable="publisher"/> </group> </if> <else> <group delimiter=", "> <text variable="publisher"/> <text variable="publisher-place"/> </group> </else> </choose> </macro> <macro name="event"> <choose> <if type="paper-conference spee
}