mirror of
https://gitlab.com/walljm/dynamicbible.git
synced 2025-07-27 17:39:49 -04:00
125 lines
4.0 KiB
TypeScript
125 lines
4.0 KiB
TypeScript
![]() |
/// <reference path="../typings/browser/ambient/jquery/index.d.ts" />
|
|||
|
/// <reference path="types.ts" />
|
|||
|
import { Injectable } from "@angular/core";
|
|||
|
import { Observable } from "rxjs/Observable";
|
|||
|
import { Http, Response } from "@angular/http";
|
|||
|
|
|||
|
@Injectable()
|
|||
|
export class StrongsService
|
|||
|
{
|
|||
|
result: StrongsResult;
|
|||
|
count = 0;
|
|||
|
|
|||
|
constructor(private http: Http)
|
|||
|
{
|
|||
|
}
|
|||
|
getStrongs(sn: number, dict: string): StrongsResult
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
const self = this;
|
|||
|
this.result = {
|
|||
|
prefix: "",
|
|||
|
sn: -1,
|
|||
|
strongs: [],
|
|||
|
def: null,
|
|||
|
rmac: [],
|
|||
|
crossrefs: [],
|
|||
|
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)
|
|||
|
{
|
|||
|
self.result.strongs = d;
|
|||
|
},
|
|||
|
error: function (request, status, error)
|
|||
|
{
|
|||
|
//Util.HandleError(error);
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
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)
|
|||
|
{
|
|||
|
self.result.crossrefs = d;
|
|||
|
},
|
|||
|
error: function (request, status, error)
|
|||
|
{
|
|||
|
//Util.HandleError(error);
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
if (dict === "grk")
|
|||
|
{
|
|||
|
url = `data/rmac/rs${Math.ceil(sn / 1000)}.json`;
|
|||
|
let rmac_cross_references: RMACCrossReference[];
|
|||
|
|
|||
|
// rmac is a two get process.
|
|||
|
$.ajax({
|
|||
|
async: false,
|
|||
|
type: "GET",
|
|||
|
url: url,
|
|||
|
dataType: "json",
|
|||
|
success: function (d: RMACCrossReference[], t, x)
|
|||
|
{
|
|||
|
rmac_cross_references = d;
|
|||
|
},
|
|||
|
error: function (request, status, error)
|
|||
|
{
|
|||
|
//Util.HandleError(error);
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
// 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)
|
|||
|
{
|
|||
|
url = `data/rmac/r-${this.result.rmaccode.substring(0, 1)}.json`;
|
|||
|
$.ajax({
|
|||
|
async: false,
|
|||
|
type: "GET",
|
|||
|
url: url,
|
|||
|
dataType: "json",
|
|||
|
success: function (d: RMACDefinition[], t, x)
|
|||
|
{
|
|||
|
self.result.rmac = d;
|
|||
|
},
|
|||
|
error: function (request, status, error)
|
|||
|
{
|
|||
|
//Util.HandleError(error);
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
return this.result;
|
|||
|
} catch (err)
|
|||
|
{
|
|||
|
//Util.HandleError(err);
|
|||
|
}
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
}
|