2016-09-12 18:13:56 -04:00
|
|
|
|
/// <reference path="../typings/browser/ambient/jquery/index.d.ts" />
|
|
|
|
|
/// <reference path="types.ts" />
|
|
|
|
|
import { Injectable } from "@angular/core";
|
2016-12-01 10:39:04 -05:00
|
|
|
|
import { Http } from "@angular/http";
|
2016-09-12 18:13:56 -04:00
|
|
|
|
|
|
|
|
|
@Injectable()
|
2016-12-27 21:10:00 -05:00
|
|
|
|
export class StrongsService
|
|
|
|
|
{
|
2016-09-12 18:13:56 -04:00
|
|
|
|
result: StrongsResult;
|
|
|
|
|
count = 0;
|
|
|
|
|
|
2016-12-27 21:10:00 -05:00
|
|
|
|
constructor(private http: Http)
|
|
|
|
|
{
|
2016-09-12 18:13:56 -04:00
|
|
|
|
}
|
2016-12-27 21:10:00 -05:00
|
|
|
|
|
2016-12-27 17:23:20 -05:00
|
|
|
|
getResult(sn: number, dict: string): StrongsResult
|
2016-12-27 21:10:00 -05:00
|
|
|
|
{
|
|
|
|
|
const self = this;
|
|
|
|
|
this.result = {
|
|
|
|
|
prefix: "",
|
|
|
|
|
sn: -1,
|
|
|
|
|
strongs: [],
|
|
|
|
|
def: null,
|
|
|
|
|
rmac: null,
|
|
|
|
|
crossrefs: null,
|
|
|
|
|
rmaccode: ""
|
|
|
|
|
};
|
|
|
|
|
let url = dict + Math.ceil(sn / 100) + ".json";
|
|
|
|
|
if (dict === "grk")
|
|
|
|
|
{
|
|
|
|
|
self.result.prefix = "G";
|
|
|
|
|
if (sn > 5624) return this.result;
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
self.result.prefix = "H";
|
|
|
|
|
if (sn > 8674) return this.result;
|
|
|
|
|
}
|
|
|
|
|
this.result.sn = sn;
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
async: false,
|
|
|
|
|
type: "GET",
|
|
|
|
|
url: `data/strongs/${url}`,
|
|
|
|
|
dataType: "json",
|
|
|
|
|
success: function (d: StrongsDefinition[], t, x)
|
2016-09-12 18:13:56 -04:00
|
|
|
|
{
|
2016-12-27 21:10:00 -05:00
|
|
|
|
self.result.strongs = d;
|
|
|
|
|
},
|
|
|
|
|
error: function (request, status, error)
|
2016-09-12 18:13:56 -04:00
|
|
|
|
{
|
2016-12-27 21:10:00 -05:00
|
|
|
|
console.log(error);
|
2016-09-12 18:13:56 -04:00
|
|
|
|
}
|
2016-12-27 21:10:00 -05:00
|
|
|
|
});
|
2016-09-12 18:13:56 -04:00
|
|
|
|
|
2016-12-27 21:10:00 -05:00
|
|
|
|
self.result.def = self.result.strongs.find(el => (el.i === this.result.prefix + this.result.sn));
|
|
|
|
|
self.result.strongs = [];
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
async: false,
|
|
|
|
|
type: "GET",
|
|
|
|
|
url: `data/strongscr/cr${url}`,
|
|
|
|
|
dataType: "json",
|
|
|
|
|
success: function (d: StrongsCrossReference[], t, x)
|
|
|
|
|
{
|
|
|
|
|
for (let cr of d)
|
2016-09-12 18:13:56 -04:00
|
|
|
|
{
|
2016-12-27 21:10:00 -05:00
|
|
|
|
if (cr.id.toUpperCase() == self.result.prefix + self.result.sn)
|
|
|
|
|
{
|
|
|
|
|
self.result.crossrefs = cr;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-09-12 18:13:56 -04:00
|
|
|
|
}
|
2016-12-27 21:10:00 -05:00
|
|
|
|
},
|
|
|
|
|
error: function (request, status, error)
|
|
|
|
|
{
|
|
|
|
|
console.log(error);
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-09-12 18:13:56 -04:00
|
|
|
|
|
2016-12-27 21:10:00 -05:00
|
|
|
|
if (dict === "grk")
|
|
|
|
|
{
|
|
|
|
|
url = `data/rmac/rs${Math.ceil(sn / 1000)}.json`;
|
|
|
|
|
let rmac_cross_references: RMACCrossReference[];
|
2016-09-12 18:13:56 -04:00
|
|
|
|
|
2016-12-27 21:10:00 -05:00
|
|
|
|
// rmac is a two get process.
|
2016-09-12 18:13:56 -04:00
|
|
|
|
$.ajax({
|
|
|
|
|
async: false,
|
|
|
|
|
type: "GET",
|
2016-12-27 21:10:00 -05:00
|
|
|
|
url: url,
|
2016-09-12 18:13:56 -04:00
|
|
|
|
dataType: "json",
|
2016-12-27 21:10:00 -05:00
|
|
|
|
success: function (d: RMACCrossReference[], t, x)
|
|
|
|
|
{
|
|
|
|
|
rmac_cross_references = d;
|
2016-09-12 18:13:56 -04:00
|
|
|
|
},
|
|
|
|
|
error: function (request, status, error)
|
|
|
|
|
{
|
2016-12-27 21:10:00 -05:00
|
|
|
|
console.log(error);
|
2016-09-12 18:13:56 -04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-12-27 21:10:00 -05:00
|
|
|
|
// deal with RMAC
|
|
|
|
|
this.result.rmaccode = $.grep<RMACCrossReference>(rmac_cross_references, (el, i) => { if (el.i == sn + "") { return true; } else { return false; } })[0].r;
|
|
|
|
|
if (this.result.rmaccode != undefined)
|
2016-09-12 18:13:56 -04:00
|
|
|
|
{
|
2016-12-27 21:10:00 -05:00
|
|
|
|
url = `data/rmac/r-${this.result.rmaccode.substring(0, 1)}.json`;
|
2016-09-12 18:13:56 -04:00
|
|
|
|
$.ajax({
|
|
|
|
|
async: false,
|
|
|
|
|
type: "GET",
|
|
|
|
|
url: url,
|
|
|
|
|
dataType: "json",
|
2016-12-27 21:10:00 -05:00
|
|
|
|
success: function (d: RMACDefinition[], t, x)
|
2016-09-12 18:13:56 -04:00
|
|
|
|
{
|
2016-12-27 21:10:00 -05:00
|
|
|
|
for (let rmac of d)
|
|
|
|
|
{
|
|
|
|
|
if (rmac.id.toLowerCase() == self.result.rmaccode)
|
|
|
|
|
{
|
|
|
|
|
self.result.rmac = rmac;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-12 18:13:56 -04:00
|
|
|
|
},
|
|
|
|
|
error: function (request, status, error)
|
|
|
|
|
{
|
2016-12-27 21:10:00 -05:00
|
|
|
|
console.log(error);
|
2016-09-12 18:13:56 -04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-27 21:10:00 -05:00
|
|
|
|
return this.result;
|
2016-09-12 18:13:56 -04:00
|
|
|
|
}
|
|
|
|
|
}
|