Warning: session_start(): open(/var/lib/php/sessions/sess_bjqovln1953867i5kbg8kt0qm4, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
//set flag alwaysSetGlobalIDs. // legacy conversion
set flag NoNanoHTTPD.
concept BEAObject > ConceptWithGlobalID {
new Ref mirrorPost;
void change :: after {
((GazelleBEA) botMod()).rstUpdateBEAMirrors.add(this);
}
void delete :: before {
cdelete(mirrorPost!);
}
void updateMirrorPost {
GazelleBEA mod = cast botMod();
if (isDeleted() || !mod.mirrorBEAObjects) ret;
if (!mirrorPost.has())
cset(this, mirrorPost := cnew UserPost(
type := "BEA Object",
creator := mod.internalUser(),
botInfo := "BEA Mirror Bot"));
S text = structureString();
cset(mirrorPost!,
title := str(this),
+text);
}
S structureString() {
S text = "Error";
pcall {
structure_Data data = new {
structure_ClassInfo newClass(Class c) {
structure_ClassInfo info = super.newClass(c);
if (c == Concept.Ref.class) {
info.special = true;
info.serializeObject = o -> {
Concept cc = cast deref((Concept.Ref) o);
//append("cu CRef " + (cc != null ? str(cc.id) : "null"), 3);
if (cc cast BEAObject)
append("CRef(gid=" + quote(cc.globalID()) + ")", 6);
else if (cc != null)
append("CRef(id=" + cc.id + ")", 6);
else
append("CRef", 1);
};
}
ret info;
}
void setFields(structure_ClassInfo info, L fields) {
if (isSubclassOf(info.c, BEAObject)) {
// Don't serialize "refs" and "backRefs" fields
removeAll(fields,
getField(BEAObject, "refs"),
getField(BEAObject, "backRefs"));
}
super.setFields(info, fields);
}
};
S struct = structure(this, data);
struct = dropLoadableUtilsPackageFromStruct(struct);
text = indentStructureString_firstLevels(1, struct);
}
ret text;
}
toString {
S type = strOrNull(cget type(this));
if (nempty(type)) {
S s = type + " " + id;
if (eqic(type, "Match"))
s += " " + this.~mapping;
ret s;
}
ret super.toString();
}
}
module GazelleBEA > DynGazelleRocks {
switchable bool mirrorBEAObjects; // don't do it for now
void init {
super.init();
botName = heading = adminName = "Gazelle BEA";
set enableVars;
set showTalkToBotLink;
unset phoneNumberSpecialInputField;
}
start {
set showCRUDToEveryone;
// mirror all objects to be sure
rstUpdateBEAMirrors.addAll(list(BEAObject));
}
void makeIndices :: after {
indexConceptFieldDesc(BEAObject, "_modified");
indexConceptFieldIC(BEAObject, "type");
indexConceptField(BEAObject, "input"); // e.g. for counting how many matches we have for a given input
}
L crudClasses(Req req) {
ret listPlus(super.crudClasses(req), BEAObject);
}
S authFormHeading() {
ret h3("Gazelle BEA");
}
void makeFramer(Req req) {
super.makeFramer(req);
req.framer.renderTitle = () -> h1(ahref(baseLink + "/", "Gazelle BEA")
+ " " + htmlEncode2(req.framer.title));
}
HCRUD_Concepts crudData(Class c, Req req) {
HCRUD_Concepts cc = super.crudData(c, req);
if (c == BEAObject) {
cc.humanizeFieldNames = false;
cc.convertConceptValuesToRefs = true;
cc.itemName = () -> "BEA Object";
cc.getObjectForDuplication = id -> {
MapSO item = cc.getObjectForDuplication_base(id);
item.put(creator := req.auth.user!); // set default creator to current user
item.put(createdFrom := getConcept(toLong(id)));
ret item;
};
}
ret cc;
}
HCRUD makeCRUD(Class c, Req req, HTMLFramer1 framer) {
HCRUD crud = super.makeCRUD(c, req, framer);
if (c == BEAObject) {
crud.cellColumnToolTips = true;
crud.unshownFields = litset("mirrorPost");
HCRUD_Concepts cc = cast crud.data;
crud.massageFormMatrix = (map, matrix) -> {
S refSelector =
crud.renderInput("newField_conceptValue",
cc.makeConceptsComboBox("newField_conceptValue", BEAObject), null)
+ hjs([[$("[name=newField_conceptValue]").hide()]]);
/*S refSelector =
hselect_list(name := "newField_conceptValue",
onchange := [[function() {
var value = this.value;
$("[name=newField_value]").toggle(value == "String");
$("[name=newField_conceptValue]").toggle(value == "BEAObject");
}]]);*/
LS types = ll("String", "BEAObject");
//S typeSelector = crud.renderComboBox("newField_type", "String", types, false);
S typeSelector = hselect_list(types, name := "newField_type",
onchange := [[
var value = this.value;
$("[name=newField_value]").toggle(value == "String");
$("#newField_refBox").toggle(value == "BEAObject");
]]);
matrix.add(ll("Add field", htmlTable2_noHtmlEncode(ll(
ll("Name", htextfield newField_name(),
"Value",
// string input
htextfield newField_value(),
span(refSelector, id := "newField_refBox", display := "none"),
"Type", typeSelector
)),
noHeader := true)));
};
crud.preprocessUpdateParams = params -> {
params = cloneMap(params);
// drop empty strings
//removeFromMapWhereValue(params, v -> eq(v, ""));
params = mapValues(params, v -> eq(v, "") ? null : v);
S name = params.get("newField_name"),
type = params.get("newField_type"),
refValue = params.get("newField_conceptValue"),
value = params.get("newField_value");
if (eq(type, "BEAObject")) {
value = refValue;
params.put("metaInfo_" + name, "concept");
}
if (eq(value, "")) value = null;
if (nempty(name) /*&& neqOneOf(value, null, "")*/)
params.put(crud.fieldPrefix + name, value);
ret params;
};
}
ret crud;
}
O serveBotFunction(Req req, S function, Map data, User user) {
if (eq(function, "beaList")) {
long changedAfter = toLong(data.get("changedAfter"));
double pollFor = min(bot_maxPollSeconds, toLong(data.get("pollFor"))); // how long to poll (seconds)
long startTime = sysNow();
// We're super-anal about catching all changes. This will probably never trigger
if (changedAfter > 0 && changedAfter == now()) sleep(1);
Cl objects;
while true {
objects = changedAfter == 0 ? list(BEAObject)
: conceptsWithFieldGreaterThan_sorted(BEAObject, _modified := changedAfter);
// return when there are results, no polling or poll expired
if (nempty(objects) || pollFor == 0 || elapsedSeconds_sysNow(startTime) >= pollFor)
ret serveJSON_breakAtLevels(2, result := map(objects, obj ->
litorderedmap(gid := str(obj.globalID()), struct := obj.structureString())
));
// sleep and try again
sleep(bot_pollInterval);
}
}
ret super.serveBotFunction(req, function, data, user);
}
transient ReliableSingleThread_Multi rstUpdateBEAMirrors = new(100, c -> c.updateMirrorPost());
O serveOtherPage2(Req req) null {
printVars_str serveOtherPage2(uri := req.uri);
try object super.serveOtherPage2(req);
S uri = dropTrailingSlashIfNemptyAfterwards(req.uri);
if (eqOneOf(uri, "/inputs", "/inputs-v2"))
ret renderBEAObjectTable(req, "input");
if (eq(uri, "/patterns"))
ret renderBEAObjectTable(req, "pattern");
if (eq(uri, "/matches"))
ret renderBEAObjectTable(req, "match");
if (!inMasterMode(req)) null;
if (eq(uri, "/uploadInputs"))
ret serveUploadTexts(req, "Input");
if (eq(uri, "/uploadPatterns"))
ret serveUploadTexts(req, "Pattern");
}
O renderBEAObjectTable(Req req, S type) {
{
HCRUD crud = makeCRUD(BEAObject, req);
crud.disableAllMutationRights();
crud.baseLink = req.uri();
((HCRUD_Concepts) crud.data).ciFilters = litmap(+type);
makeFramer(req);
HTMLFramer1 framer = req.framer;
S baseTitle = framer.title;
S theTitle = firstToUpper(plural(type));
crud.makeFrame = (title, contents) -> {
framer.title = joinNemptiesWithVBar(hTitleClean(theTitle), baseTitle);
ret h1(title) + contents;
};
crud.processSortParameter(req.params);
framer.add(crud.renderPage(req.params));
ret framer.render();
}
}
O serveUploadTexts(Req req, S type) {
S inputs = req.get("text");
new LS output;
if (nempty(inputs)) {
for (S text : tlft(inputs)) {
Pair p = uniqCI2_sync BEAObject(+type, +text);
if (cget uploadedBy(p.a) == null)
cset(p.a, uploadedBy := req.auth.user);
output.add(type + " " + (p.b ? "added" : "exists")
+ " (ID " + p.a.id + "): " + text);
}
}
ret h2("Upload " + plural(type))
+ hpostform(
p(plural(type) + " (one per line):")
+ p(htextarea(inputs, name := "text"))
+ pIfNempty(htmlEncode_nlToBR(lines(output)))
+ hsubmit("Upload " + plural(type)));
}
void reactAllInputsWithSomePatterns() {
forEach reactInputWithSomePatterns(beaObjectsOfType("input"));
}
void reactInputWithSomePatterns(BEAObject input) {
S text = getString text(input);
if (empty(text)) ret;
int max = 3, n = countConceptsWhereIC BEAObject(+input, type := "match");
for (BEAObject pattern : conceptsWhereIC BEAObject(type := "Pattern")) {
if (n >= max) break;
if (reactInputWithPattern(input, pattern) != null)
++n;
++n;
}
}
SS matchInputWithPattern(BEAObject input, BEAObject pattern) {
ret flexMatchAngleBracketVarsIC_first(getString text(pattern), getString text(input));
}
BEAObject reactInputWithPattern(BEAObject input, BEAObject pattern) {
SS mapping = matchInputWithPattern(pattern, input);
if (mapping == null) null;
ret cnew(BEAObject,
type := "Match",
+input,
+pattern,
+mapping);
}
Cl beaObjectsOfType(S type) {
ret conceptsWhereCI BEAObject(+type);
}
} // end of module