mirror of
https://gitlab.com/walljm/dynamicbible.git
synced 2025-07-25 16:29:49 -04:00
108 lines
3.2 KiB
TypeScript
108 lines
3.2 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 BibleService
|
|
{
|
|
chapters: BiblePassage[];
|
|
result: BiblePassageResult;
|
|
count: number = 0;
|
|
|
|
constructor(private http: Http)
|
|
{
|
|
}
|
|
|
|
getPassage(section: Section): BiblePassageResult
|
|
{
|
|
try
|
|
{
|
|
var self = this;
|
|
this.chapters = []; // the verses from the chapter.
|
|
this.result = {
|
|
cs: [],
|
|
testament: "",
|
|
ref: "",
|
|
id: 0
|
|
};
|
|
this.count = Number(section.end.chapter) - Number(section.start.chapter) + 1;
|
|
|
|
for (let i = Number(section.start.chapter); i <= Number(section.end.chapter); i++)
|
|
{
|
|
let url = "data/bibles/kjv_strongs/" + section.start.book + "-" + i + ".json";
|
|
jQuery.ajax({
|
|
async: false,
|
|
type: "GET",
|
|
url: url,
|
|
dataType: "json",
|
|
success: function (d: BiblePassage, t, x)
|
|
{
|
|
self.chapters.push(d);
|
|
},
|
|
error: function (request, status, error)
|
|
{
|
|
//Util.HandleError(error);
|
|
}
|
|
});
|
|
}
|
|
|
|
for (let j = 0; j < this.chapters.length; j++)
|
|
{
|
|
let vss: BibleVerse[] = [];
|
|
let start;
|
|
let end;
|
|
|
|
// figure out the start verse.
|
|
if (j == 0)
|
|
{
|
|
start = section.start.verse;
|
|
} else
|
|
{
|
|
start = 1;
|
|
}
|
|
|
|
// figure out the end verse
|
|
if ((j + 1) == this.chapters.length)
|
|
{
|
|
end = section.end.verse;
|
|
} else
|
|
{
|
|
end = "*";
|
|
}
|
|
|
|
// get the verses requested.
|
|
let tvs = this.chapters[j].vss.length;
|
|
if (end == "*" || end > tvs)
|
|
{
|
|
end = tvs;
|
|
}
|
|
|
|
for (let i = start; i <= end; i++)
|
|
{
|
|
// we're using c based indexes here, so the index is 1 less than the verse #.
|
|
vss.push(this.chapters[j].vss[i - 1]);
|
|
}
|
|
|
|
this.result.cs.push({
|
|
"ch": this.chapters[j].ch,
|
|
"vss": vss
|
|
});
|
|
}
|
|
|
|
if (section.start.book >= 40)
|
|
{
|
|
this.result.testament = "new";
|
|
} else
|
|
{
|
|
this.result.testament = "old";
|
|
}
|
|
return this.result;
|
|
} catch (err)
|
|
{
|
|
//Util.HandleError(err);
|
|
}
|
|
return null;
|
|
}
|
|
} |