FSN#39312 Verder ontsluiten van modellen via de API

svn path=/Website/trunk/; revision=33021
This commit is contained in:
Jos Groot Lipman
2017-03-02 16:52:23 +00:00
parent 44341f8ba8
commit 68a774c4c2
14 changed files with 138 additions and 89 deletions

View File

@@ -1369,7 +1369,7 @@ function generic_REST_GET(model, gparams)
sql += " ORDER BY " + orderbys.join(", "); // TODO: Altijd goed met includes?
// Probeer ook nog de 1e include te sorteren. Fraaier met subframes in scaffolding
if (params.include && params.include.length && model.includes)
if (params.include && params.include.length && model.includes && params.include[0] in model.includes)
{
var inc0 = model.includes[params.include[0]].model;
if (inc0.fields["sequence"])

View File

@@ -109,6 +109,7 @@ var api2_mapper = {
function api2_dispatch(api2_name)
{
api2_name = api2_name.toLowerCase();
if (api2_name in api2_mapper)
return api2_mapper[api2_name];
@@ -120,6 +121,4 @@ function api2_dispatch(api2_name)
return fullname;
}
}
// FAC_LCL('lcl_rap_expression', 'SQL expressie', 'SQL expression', 'SQL-Ausdruck', 'Expressie SQL')
%>

View File

@@ -209,6 +209,8 @@ api2_rest = {
{
// TODO: Onderstaande in een of ander standaardformaat opleveren?
var result = { id: model.records_name,
"name": model.record_title,
"names": model.records_title,
methods: [],
includes: [],
fields: []
@@ -230,7 +232,9 @@ api2_rest = {
result.fields.push({ id: fld,
filter: model.fields[fld].filter,
type: model.fields[fld].typ,
label: model.fields[fld].label
label: model.fields[fld].label,
required: model.fields[fld].required,
valuelist: model.fields[fld].LOV && api2.splitLOV(model.fields[fld].LOV)
});
}
}
@@ -426,7 +430,7 @@ api2_rest = {
case "html":
Response.ContentType = "text/html";
var antwoord = JSON.stringify(resultdata, null, 2);
var str_antwoord = "<!DOCTYPE html><html><head></head><body><pre>"
var str_antwoord = "<!DOCTYPE html><html><head><title>{0}</title></head><body><pre>".format(single?model.record_name:model.records_name)
+ Server.HTMLEncode(antwoord)
+ "</pre></body></html>";
break;
@@ -771,6 +775,8 @@ var simple_json2xml = (function (undefined) {
if (obj.hasOwnProperty(i)) {
var value = obj[i],
type = typeof value;
if (value === obj) // bij merged_model zouden we hier oneindige recursie krijgen
continue;
if (value instanceof Array && type == 'object') {
for (var sub in value) {
xml += simple_json2xml(value[sub]);

View File

@@ -4,7 +4,7 @@
File: model_alg_srtgebouw.inc
Description: Vanuit CodeCharge gegenereerd model voor alg_srtgebouw
Description: Model voor alg_srtgebouw
Context:
@@ -14,10 +14,8 @@
<%
function model_alg_srtgebouw()
{
var tab_key = getQParamInt("alg_srtgebouw_key", -1);
this.records_name = "alg_buildingfunctions";
this.record_name = "alg_buildingfunction";
this.records_name = "buildingfunctions";
this.record_name = "buildingfunction";
this.table = "alg_srtgebouw";
this.primary = "alg_srtgebouw_key";
this.soft_delete = "alg_srtgebouw_verwijder";

View File

@@ -4,7 +4,7 @@
File: model_alg_srtterreinsector.inc
Description: Vanuit CodeCharge gegenereerd model voor alg_srtterreinsector
Description: Model voor alg_srtterreinsector
Context:
@@ -14,8 +14,8 @@
<%
function model_alg_srtterreinsector()
{
this.records_name = "alg_terrainfunctions";
this.record_name = "alg_terrainfunction";
this.records_name = "terrainfunctions";
this.record_name = "terrainfunction";
this.table = "alg_srtterreinsector";
this.primary = "alg_srtterreinsector_key";
this.soft_delete = "alg_srtterreinsector_verwijder";

View File

@@ -20,8 +20,9 @@ model_apis =
primary: "id",
records_name: "apis",
record_name: "api",
fields : { "id" : { xxdbs: "fac_usrrap_key", typ: "varchar", label: "Api", filter: "exact" },
"name" : { xxdbs: "fac_usrrap_key", typ: "varchar", label: "Api", filter: "exact" }
fields : { "id" : { typ: "varchar", label: "Api", filter: "exact" },
"module" : { typ: "varchar", label: "Module", filter: "exact" },
"name" : { typ: "varchar", label: "Api", filter: "exact" }
},
REST_GET: function _GET(params)
@@ -32,8 +33,9 @@ model_apis =
var api2_names = [];
for (var dispatch in api2_mapper)
{
var module = api2_mapper[dispatch].substr(9, 3).toUpperCase();
// TODO: kijken of er een L() bestaat voor de api2_mapper filenaam
api2_names.push({ id: dispatch, name: "X-" + dispatch });
api2_names.push({ id: dispatch, name: dispatch, modulecode: module, module: L("lcl_module_" + module) });
}
var fullpath = Server.MapPath("./appl/api2");
@@ -57,15 +59,6 @@ model_apis =
return api2_names;
},
PUT: function (params) /* update api */
{
},
POST: function (params) /* new api */
{
},
DELETE: function (params) /* delete api */
{
},
search: { autosearch: true },
list: { default_url: "api2/{0}.scf" }

View File

@@ -26,7 +26,7 @@ function model_doc()
this.fields = {};
for (var i = 0; i < apis.length; i++)
{
this.fields[ apis[i].id ] = { label: apis[i].name };
this.fields[ apis[i].id ] = { label: apis[i].name, module: apis[i].module };
}
this.REST_GET = generic_REST_GET(this, {});

View File

@@ -7,13 +7,16 @@
<html>
<head>
<link rel="stylesheet" type="text/css" href="../appl/api2/reference.css?"/>
<title>FACILITOR&#174; API reference</title>
</head>
<body>
<h1>FACILITOR&#174; API reference</h1>
<xsl:element name="ul">
<xsl:for-each select="/api/fields/*">
<xsl:sort select="@module" />
<xsl:element name="li">
<xsl:element name="a">
<xsl:value-of select="module"/>
&#xA0;<xsl:element name="a">
<xsl:attribute name="href">../api2/<xsl:value-of select="local-name()"/>.doc</xsl:attribute>
<xsl:value-of select="local-name()"/>
</xsl:element>

View File

@@ -52,7 +52,7 @@ function model_fac_profiel()
this.includes = {
"profile_values": {
"profilevalues": {
"model": new model_fac_profielwaarde(),
"joinfield": "profile",
"enable_update": true,

View File

@@ -15,10 +15,10 @@
function model_fac_srtnotificatie(cust)
{
this.records_name = "notificationtypes";
this.record_name = "notificationtype";
this.table = "fac_srtnotificatie";
this.primary = "fac_srtnotificatie_key";
this.records_name = "fac_srtnotificaties";
this.record_name = "fac_srtnotificatie";
this.autfunction = "WEB_PRSSYS";
this.record_title = L("fac_srtnotificatie");
this.records_title = L("fac_srtnotificatie_m");
@@ -26,7 +26,7 @@ function model_fac_srtnotificatie(cust)
this.fields = {
"id": {
"dbs": "fac_srtnotificatie_key",
"label": "Key",
"label": L("lcl_key"),
"typ": "key",
"required": true,
"seq": "fac_s_fac_srtnotificatie_key",
@@ -54,7 +54,7 @@ function model_fac_srtnotificatie(cust)
"LOV": fill_srtnotificatie_LOV(),
"emptyoption": null
},
"notification_url": {
"notificationurl": {
"dbs": "fac_srtnotificatie_url",
"label": L("fac_srtnotificatie_url"),
"typ": "varchar",
@@ -66,7 +66,7 @@ function model_fac_srtnotificatie(cust)
"typ": "varchar",
"readonly": true
},
"notification_mode": {
"notificationmode": {
"dbs": "fac_srtnotificatie_mode",
"label": "",
"typ": "number",
@@ -121,40 +121,43 @@ function model_fac_srtnotificatie(cust)
"dbs": "fac_srtnotificatie_usermode",
"label": L("fac_srtnotificatie_usermode"),
"typ": "check0",
"listfunction": fnshowusermode
"listfunction": fnshowusermode,
"multiedit": true
},
"mail_building": {
"mailbuilding": {
"dbs": "fac_srtnotificatie_gebouw",
"label": L("fac_srtnotificatie_gebouw"),
"typ": "check0",
"listfunction": fnshowmailbuilding
"listfunction": fnshowmailbuilding,
"multiedit": true
},
"delay": {
"dbs": "fac_srtnotificatie_delay",
"label": L("fac_srtnotificatie_delay"),
"typ": "number",
"required": true,
"defaultvalue": "0"
"defaultvalue": "0",
"multiedit": true
},
"mode_status": {
"modestatus": {
"dbs": "notimode.status",
"label": L("fac_srtnotificatie_status"),
"typ": "varchar",
"hidden_fld": true
},
"mode_email": {
"modeemail": {
"dbs": "notimode.email",
"label": L("fac_srtnotificatie_mail"),
"typ": "varchar",
"hidden_fld": true
},
"mode_sms": {
"modesms": {
"dbs": "notimode.sms",
"label": L("fac_srtnotificatie_sms"),
"typ": "varchar",
"hidden_fld": true
},
"mode_alert": {
"modealert": {
"dbs": "notimode.portal",
"label": L("fac_srtnotificatie_alert"),
"typ": "varchar",
@@ -163,7 +166,7 @@ function model_fac_srtnotificatie(cust)
};
if (!S("puo_smsaccount"))
this.fields.notification_mode.bits[0].radios.splice(2, 1);
this.fields.notificationmode.bits[0].radios.splice(2, 1);
var ext_sql = "(SELECT fac_srtnotificatie_key"
+ " , DECODE(BITAND(fac_srtnotificatie_mode, 1), 1,"+ safe.qL("lcl_on") +", '') status"
@@ -179,6 +182,24 @@ function model_fac_srtnotificatie(cust)
}
};
function fill_srtnotificatie_LOV()
{
var xmlnodeLOV = "";
var sql = "SELECT distinct fac_srtnotificatie_xmlnode"
+ " , NVL(fac_srtnotificatie_xmlnode,'<empty>') xmlnode_lov"
+ " FROM fac_srtnotificatie"
+ " ORDER BY 1 NULLS FIRST";
var oRs = Oracle.Execute(sql);
while (!oRs.eof)
{
var xmlnode = oRs("fac_srtnotificatie_xmlnode").Value;
xmlnodeLOV += (xmlnodeLOV?";":"") + xmlnode + ";" + oRs("xmlnode_lov").Value;
oRs.moveNext();
}
oRs.Close();
return xmlnodeLOV;
}
function xxx_srtkenmerk_sql()
{
var sql = "(select sk.mld_srtkenmerk_key srtkenmerk_key"
@@ -201,7 +222,7 @@ function model_fac_srtnotificatie(cust)
this.fields.xmlnode.readonly = false;
this.fields.xmlnode.required = true;
this.fields.description.required = true;
this.fields.notification_url.readonly = false;
this.fields.notificationurl.readonly = false;
this.fields.group.readonly = false;
get_param.GET.wheres.push("UPPER(SUBSTR(fac_srtnotificatie_code, 1, 4)) = 'CUST' ");
@@ -218,7 +239,7 @@ function model_fac_srtnotificatie(cust)
// Voorlopig mag alleen voor meldingen en opdrachten het vinkje 'E-mail sturen naar gebouw'
// gezet worden
if (iscust == 1 || !inArray(obj.name.substring(0,3), ["MLD", "ORD"]))
fld.mail_building.readonly = true;
fld.mailbuilding.readonly = true;
if (inArray(obj.name, ["MLDAFM", "MLDAFR", "MLDUPD"]))
{

View File

@@ -18,10 +18,10 @@
function model_res_ruimte()
{
this.records_name = "bookingrooms";
this.record_name = "bookingroom";
this.table = "res_ruimte";
this.primary = "res_ruimte_key";
this.records_name = "res_ruimtes";
this.record_name = "res_ruimte";
this.soft_delete = "res_ruimte_verwijder";
this.soft_expire = "res_ruimte_vervaldatum";
this.autfunction = "WEB_RESMSU";
@@ -31,7 +31,7 @@ function model_res_ruimte()
this.fields = {
"id": {
"dbs": "res_ruimte_key",
"label": "Key",
"label": L("lcl_key"),
"typ": "key",
"required": true,
"filter": "exact",
@@ -58,12 +58,12 @@ function model_res_ruimte()
"label": L("res_ruimte_volgnummer"),
"typ": "number"
},
"res_ruimte_info_url": {
"infourl": {
"dbs": "res_ruimte_info_url",
"label": L("res_ruimte_info_url"),
"typ": "varchar"
},
"locatiekey": {
"locatiekey": { // liever location maar zo komt het uit de plaatsselector
"dbs": "res_v_alg_ruimte_gegevens.alg_locatie_key",
"label": L("lcl_location"),
"typ": "key",
@@ -76,7 +76,7 @@ function model_res_ruimte()
},
"foreignfiltercode": null // Ook facilitor irrelevant
},
"catalog": {
"bookingdiscipline": {
"dbs": "res_discipline_key",
"label": L("res_discipline_key"),
"typ": "key",
@@ -94,121 +94,127 @@ function model_res_ruimte()
"label": L("res_ruimte_begintijd"),
"typ": "float",
"LOV": api2.getTimetable(),
"emptyoption": L("lcl_res_standaard").format(toTimeString(S("res_t1"),false))
"emptyoption": L("lcl_res_standaard").format(toTimeString(S("res_t1"),false)),
"multiedit": true
},
"close": {
"dbs": "res_ruimte_eindtijd",
"label": L("res_ruimte_eindtijd"),
"typ": "float",
"LOV": api2.getTimetable(),
"emptyoption": L("lcl_res_standaard").format(toTimeString(S("res_t2"),false))
"emptyoption": L("lcl_res_standaard").format(toTimeString(S("res_t2"),false)),
"multiedit": true
},
"blockstart": {
"dbs": "res_ruimte_begintijdblok",
"label": L("res_ruimte_begintijdblok"),
"typ": "float",
"LOV": api2.getTimetable()
"LOV": api2.getTimetable(),
"multiedit": true
},
"blockend": {
"dbs": "res_ruimte_eindtijdblok",
"label": L("res_ruimte_eindtijdblok"),
"typ": "float",
"LOV": api2.getTimetable()
"LOV": api2.getTimetable(),
"multiedit": true
},
"min_res_time": {
"minduration": {
"dbs": "res_ruimte_min_duur",
"label": L("res_ruimte_min_duur"),
"typ": "float"
"typ": "float",
"multiedit": true
},
"res_ruimte_prijs_vast": {
"fixedprice": {
"dbs": "res_ruimte_prijs_vast",
"label": L("res_ruimte_prijs_vast"),
"typ": "check"
"typ": "check",
"multiedit": true
},
"_interne_prijzen": {
"_intpricelabel": {
"dbs": "",
"label": "",
"typ": "label",
"labelvalue": L("res_ruimte_intprijs_label")
},
"res_ruimte_intprijs": {
"intpricehour": {
"dbs": "res_ruimte_intprijs",
"label": L("res_ruimte_intprijs"),
"iscurrency": true,
"typ": "float"
},
"res_ruimte_intprijs_ochtend": {
"intpricemorning": {
"dbs": "res_ruimte_intprijs_ochtend",
"label": L("res_ruimte_intprijs_ochtend"),
"iscurrency": true,
"typ": "float"
},
"res_ruimte_intprijs_middag": {
"intpriceafternoon": {
"dbs": "res_ruimte_intprijs_middag",
"label": L("res_ruimte_intprijs_middag"),
"iscurrency": true,
"typ": "float"
},
"res_ruimte_intprijs_avond": {
"intpriceevening": {
"dbs": "res_ruimte_intprijs_avond",
"label": L("res_ruimte_intprijs_avond"),
"iscurrency": true,
"typ": "float"
},
"res_ruimte_intprijs_dag": {
"intpriceday": {
"dbs": "res_ruimte_intprijs_dag",
"label": L("res_ruimte_intprijs_dag"),
"iscurrency": true,
"typ": "float"
},
"_externe_prijzen": {
"_extpricelabel": {
"dbs": "",
"label": "",
"typ": "label",
"labelvalue": L("res_ruimte_extprijs_label")
},
"res_ruimte_prijs": {
"extpricehour": {
"dbs": "res_ruimte_prijs",
"label": L("res_ruimte_prijs"),
"iscurrency": true,
"typ": "float"
},
"res_ruimte_prijs_ochtend": {
"extpricemorning": {
"dbs": "res_ruimte_prijs_ochtend",
"label": L("res_ruimte_prijs_ochtend"),
"iscurrency": true,
"typ": "float"
},
"res_ruimte_prijs_middag": {
"extpriceafternoon": {
"dbs": "res_ruimte_prijs_middag",
"label": L("res_ruimte_prijs_middag"),
"iscurrency": true,
"typ": "float"
},
"res_ruimte_prijs_avond": {
"extpriceevening": {
"dbs": "res_ruimte_prijs_avond",
"label": L("res_ruimte_prijs_avond"),
"iscurrency": true,
"typ": "float"
},
"res_ruimte_prijs_dag": {
"extpriceday": {
"dbs": "res_ruimte_prijs_dag",
"label": L("res_ruimte_prijs_dag"),
"iscurrency": true,
"typ": "float"
},
"res_ruimte_image": {
"image": {
"dbs": "res_ruimte_image",
"label": L("res_ruimte_image"),
"typ": "varchar",
"flexmodule": "RESPH"
},
"res_ruimte_groep": {
"waitingarea": {
"dbs": "res_ruimte_groep",
"label": L("res_ruimte_groep"),
"typ": "varchar"
},
"action": {
"visitoraction": {
"dbs": "bez_actie_key",
"label": L("bez_actie_key"),
"typ": "key",
@@ -221,7 +227,7 @@ function model_res_ruimte()
"filter": "exact",
"LOVinit": ""
},
"res_status_fo_key": {
"defaultstatus": {
"dbs": "res_status_fo_key",
"label": L("res_status_fo_key"),
"typ": "key",
@@ -233,12 +239,13 @@ function model_res_ruimte()
"label": L("res_ruimte_friendlyname"),
"typ": "varchar"
},
"res_ruimte_vervaldatum": {
"expirationdate": {
"dbs": "res_ruimte_vervaldatum",
"label": L("res_ruimte_vervaldatum"),
"typ": "date"
"typ": "date",
"multiedit": true
},
"res_ruimte_extern_id": {
"externalid": {
"dbs": "res_ruimte_extern_id",
"label": L("res_ruimte_extern_id"),
"typ": "varchar"
@@ -251,14 +258,14 @@ function model_res_ruimte()
this.fields.res_ruimte_extern_id.readonly = true;
this.includes = {
"rooms": {
"physicalrooms": {
"model": new model_res_alg_ruimte(),
"joinfield": "res_ruimte_key"
"joinfield": "bookingroom"
},
"configurations": {
"bookingconfigurations": {
"model": new model_res_ruimte_opstelling(),
"joinfield": "res_ruimte_key",
"multiadd": "res_opstelling_key"
"joinfield": "bookingroom",
"multiadd": "bookingconfiguration"
}
};

View File

@@ -7,9 +7,13 @@
<html>
<head>
<link rel="stylesheet" type="text/css" href="../appl/api2/reference.css?"/>
<title>API <xsl:value-of select="/api/records_name"/></title>
</head>
<body>
<h1>FACILITOR&#174; API reference: <xsl:value-of select="/api/records_name"/></h1>
<xsl:if test="/api/records_title!=''">
<h1><xsl:value-of select="/api/records_title"/></h1>
</xsl:if>
Record name: <xsl:value-of select="/api/record_name"/><br />
Records name: <xsl:value-of select="/api/records_name"/><br />
<h2>Parameters:</h2>
@@ -36,6 +40,15 @@
GET /api2/<xsl:value-of select="/api/records_name"/>.json
</xsl:element>
</div>
<xsl:for-each select="/api/includes/*">
<div class="sample">
<xsl:element name="a">
<xsl:attribute name="href">../api2/<xsl:value-of select="/api/records_name"/>.html?include=<xsl:value-of select="local-name()"/>&amp;limit=3</xsl:attribute>
<xsl:attribute name="target">_new</xsl:attribute>
GET /api2/<xsl:value-of select="/api/records_name"/>.json?include=<xsl:value-of select="local-name()"/>
</xsl:element>
</div>
</xsl:for-each>
<div class="sample">
<xsl:element name="a">
<xsl:attribute name="href">../api2/<xsl:value-of select="/api/records_name"/>.xml?limit=3</xsl:attribute>
@@ -46,7 +59,9 @@
<h2>Fields list:</h2>
<xsl:for-each select="/api/fields/*">
<h3><xsl:value-of select="local-name()"/></h3>
Name: <xsl:value-of select="local-name()"/><br />
<xsl:if test="label!=''">
Label: "<xsl:value-of select="label"/>"<br />
</xsl:if>
<xsl:if test="filter!=''">
Filter: <xsl:value-of select="filter"/><br />
</xsl:if>

View File

@@ -19,7 +19,7 @@ scaffolding(this_model,
"description",
"locatiekey",
"bookingdiscipline",
"bookingconfigurations.roomconfiguration"
"bookingconfigurations.bookingroom"
]
},
"list": {
@@ -29,8 +29,8 @@ scaffolding(this_model,
"name",
"description",
"bookingdiscipline",
"bookingconfigurations.roomconfiguration",
"rooms.ruimtekey"
"bookingconfigurations.bookingroom",
"physicalrooms.ruimtekey"
]
},
"show": {

View File

@@ -927,11 +927,18 @@ Perslid.prototype.checkAutorisation_readit = function _checkAutorisation_readit(
else
{
if (Request.QueryString("api2").Count > 0)
{
if (Request.QueryString("format") == 'doc')
{
shared.simpel_page(L("lcl_no_auth") + " ({0})".format(String(autfunction)));
}
else
{
Response.Status = '403 Forbidden';
// Response.Write(L("lcl_no_auth")); ?
Response.End();
}
}
shared.simpel_page(L("lcl_no_auth"));
}
}