Skip to content

Commit 39fabb8

Browse files
committed
Merge branch 'main' of github.com:structr/structr
2 parents f4d55ff + 631be44 commit 39fabb8

File tree

17 files changed

+383
-45
lines changed

17 files changed

+383
-45
lines changed

structr-app/src/main/resources/structr/js/frontend/frontend.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,6 @@ export class Frontend {
318318
statusHTML += '</div>';
319319
}
320320

321-
// fix positioning of inline element if it is inside an overflow container which is scrolled
322-
statusHTML = '<div style="position:relative;">' + statusHTML + '</div>';
323-
324321
// none, system-alert, inline-text-message, custom-dialog, custom-dialog-linked
325322
switch (mode) {
326323

structr-base/src/main/java/org/structr/console/Console.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ private void runCypher(final String line, final Writable writable) throws Framew
257257

258258
if (size <= maxResults) {
259259

260-
writable.print(Functions.get("to_json").apply(actionContext, null, new Object[] { result } ));
260+
writable.print(Functions.get("toJson").apply(actionContext, null, new Object[] { result } ));
261261

262262
} else {
263263

structr-base/src/main/java/org/structr/core/function/HMACFunction.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import org.structr.common.error.ArgumentCountException;
2222
import org.structr.common.error.ArgumentNullException;
2323
import org.structr.common.error.FrameworkException;
24+
import org.structr.docs.Example;
25+
import org.structr.docs.Parameter;
2426
import org.structr.docs.Signature;
2527
import org.structr.docs.Usage;
2628
import org.structr.schema.action.ActionContext;
@@ -100,8 +102,8 @@ public Object apply(final ActionContext ctx, final Object caller, final Object[]
100102
@Override
101103
public List<Usage> getUsages() {
102104
return List.of(
103-
Usage.structrScript("Usage: ${hmac(value, secret [, hashAlgorithm ])}. Example: ${hmac(\"testpayload\", \"hashSecret\", \"SHA256\")}"),
104-
Usage.javaScript("Usage: ${{Structr.hmac(value, secret [, hashAlgorithm ])}}. Example: ${{Structr.hmac(\"testpayload\", \"hashSecret\", \"SHA256\")}}")
105+
Usage.structrScript("Usage: ${hmac(value, secret [, hashAlgorithm ])}."),
106+
Usage.javaScript("Usage: ${{Structr.hmac(value, secret [, hashAlgorithm ])}}.")
105107
);
106108
}
107109

@@ -112,7 +114,33 @@ public String getShortDescription() {
112114

113115
@Override
114116
public String getLongDescription() {
115-
return "";
117+
return "Returns a keyed-hash message authentication code generated out of the given payload, secret and hash algorithm.";
118+
}
119+
120+
@Override
121+
public List<Example> getExamples() {
122+
return List.of(
123+
Example.structrScript("${hmac(to_json(me)), 'aVeryGoodSecret')}"),
124+
Example.javaScript("${{ $.hmac(JSON.stringify({key1: 'test'}), 'aVeryGoodSecret') }}")
125+
);
126+
}
127+
128+
@Override
129+
public List<String> getNotes() {
130+
return List.of(
131+
"Default value for parameter hashAlgorithm is SHA256."
132+
);
133+
}
134+
135+
@Override
136+
public List<Parameter> getParameters() {
137+
138+
return List.of(
139+
Parameter.mandatory("value", "Payload that will be converted to hash string"),
140+
Parameter.mandatory("secret", "Secret value"),
141+
Parameter.optional("hashAlgorithm", "Hash algorithm that will be used to convert the payload")
142+
143+
);
116144
}
117145

118146
@Override

structr-base/src/main/java/org/structr/core/function/HasCacheValueFunction.java

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.structr.common.error.ArgumentNullException;
2323
import org.structr.common.error.FrameworkException;
2424
import org.structr.core.parser.CacheExpression;
25+
import org.structr.docs.Example;
26+
import org.structr.docs.Parameter;
2527
import org.structr.docs.Signature;
2628
import org.structr.docs.Usage;
2729
import org.structr.schema.action.ActionContext;
@@ -63,8 +65,8 @@ public Object apply(final ActionContext ctx, final Object caller, final Object[]
6365
@Override
6466
public List<Usage> getUsages() {
6567
return List.of(
66-
Usage.structrScript("Usage: ${hasCacheValue(cacheKey)}. Example: ${hasCacheValue('mykey')}"),
67-
Usage.javaScript("Usage: ${{ Structr.hasCacheValue(cacheKey); }}. Example: ${{ Structr.hasCacheValue('mykey'); }}")
68+
Usage.structrScript("Usage: ${hasCacheValue(cacheKey)}."),
69+
Usage.javaScript("Usage: ${{ $.hasCacheValue(cacheKey); }}.")
6870
);
6971
}
7072

@@ -75,6 +77,45 @@ public String getShortDescription() {
7577

7678
@Override
7779
public String getLongDescription() {
78-
return "";
80+
81+
return """
82+
Checks if a cached value exists for the given key. Returns false if there is no stored value for the given key or if the stored value is expired.
83+
This function is especially useful if the result of a JavaScript function should be cached (see Example 2).
84+
""";
85+
}
86+
87+
@Override
88+
public List<Example> getExamples() {
89+
return List.of(
90+
Example.structrScript("${hasCacheValue('externalResult')}"),
91+
Example.javaScript("""
92+
${{
93+
let myComplexFunction = function() {
94+
// computation... for brevity just return a date string
95+
return new Date().toString();
96+
};
97+
let cacheKey = 'myKey';
98+
if ($.hasCacheValue(cacheKey)) {
99+
// retrieve cached value
100+
let cacheValue = $.getCacheValue(cacheKey);
101+
// ...
102+
// ...
103+
} else {
104+
// cache the result of a complex function
105+
let cacheResult = $.cache(cacheKey, 30, myComplexFunction());
106+
// ...
107+
// ...
108+
}
109+
}}
110+
""")
111+
);
112+
}
113+
114+
@Override
115+
public List<Parameter> getParameters() {
116+
117+
return List.of(
118+
Parameter.mandatory("key", "cache key")
119+
);
79120
}
80121
}

structr-base/src/main/java/org/structr/core/function/HasErrorFunction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ public Object apply(final ActionContext ctx, final Object caller, final Object[]
4848
public List<Usage> getUsages() {
4949
return List.of(
5050
Usage.structrScript("Usage: ${hasError()}"),
51-
Usage.javaScript("Usage: ${{ Structr.hasError() }}")
51+
Usage.javaScript("Usage: ${{ $.hasError() }}")
5252
);
5353
}
5454

5555
@Override
5656
public String getShortDescription() {
57-
return "Allows checking if an error occurred in the scripting context.";
57+
return "Allows checking if an error has been raised in the scripting context.";
5858
}
5959

6060
@Override

structr-base/src/main/java/org/structr/core/function/HasIncomingRelationshipFunction.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import org.structr.common.error.FrameworkException;
2424
import org.structr.core.graph.NodeInterface;
2525
import org.structr.core.graph.RelationshipInterface;
26+
import org.structr.docs.Example;
27+
import org.structr.docs.Parameter;
2628
import org.structr.docs.Signature;
2729
import org.structr.docs.Usage;
2830
import org.structr.schema.action.ActionContext;
@@ -114,8 +116,8 @@ public Object apply(final ActionContext ctx, final Object caller, final Object[]
114116
@Override
115117
public List<Usage> getUsages() {
116118
return List.of(
117-
Usage.structrScript("Usage: ${hasIncomingRelationship(from, to [, relType])}. Example: ${hasIncomingRelationship(me, user, 'FOLLOWS')}"),
118-
Usage.javaScript("Usage: ${{Structr.hasIncomingRelationship(from, to [, relType])}}. Example: ${{Structr.hasIncomingRelationship(Structr.get('me'), user, 'FOLLOWS')}}")
119+
Usage.structrScript("Usage: ${hasIncomingRelationship(from, to [, relType])}."),
120+
Usage.javaScript("Usage: ${{$.hasIncomingRelationship(from, to [, relType])}}.")
119121
);
120122
}
121123

@@ -126,6 +128,24 @@ public String getShortDescription() {
126128

127129
@Override
128130
public String getLongDescription() {
129-
return "";
131+
return "Returns a boolean value indicating whether **at least one** incoming relationship exists between the given entities, with an optional qualifying relationship type. See also `incoming()`, `outgoing()`, `has_relationship()` and `has_outgoing_relationship()`.";
132+
}
133+
134+
@Override
135+
public List<Example> getExamples() {
136+
return List.of(
137+
Example.structrScript("${hasIncomingRelationship(me, page, 'OWNS')}"),
138+
Example.javaScript("${{ $.hasIncomingRelationship($.me, $.page, 'OWNS') }}")
139+
);
140+
}
141+
142+
@Override
143+
public List<Parameter> getParameters() {
144+
145+
return List.of(
146+
Parameter.mandatory("from", "entity the relationship goes from"),
147+
Parameter.mandatory("to", "entity the relationship goes to"),
148+
Parameter.optional("relType", "type of relationship")
149+
);
130150
}
131151
}

structr-base/src/main/java/org/structr/core/function/HasOutgoingRelationshipFunction.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import org.structr.common.error.FrameworkException;
2424
import org.structr.core.graph.NodeInterface;
2525
import org.structr.core.graph.RelationshipInterface;
26+
import org.structr.docs.Example;
27+
import org.structr.docs.Parameter;
2628
import org.structr.docs.Signature;
2729
import org.structr.docs.Usage;
2830
import org.structr.schema.action.ActionContext;
@@ -114,8 +116,8 @@ public Object apply(final ActionContext ctx, final Object caller, final Object[]
114116
@Override
115117
public List<Usage> getUsages() {
116118
return List.of(
117-
Usage.structrScript("Usage: ${hasOutgoingRelationship(from, to [, relType])}. Example: ${hasOutgoingRelationship(me, user, 'FOLLOWS')}"),
118-
Usage.javaScript("Usage: ${{Structr.hasOutgoingRelationship(from, to [, relType])}}. Example: ${{Structr.hasOutgoingRelationship(Structr.get('me'), user, 'FOLLOWS')}}")
119+
Usage.structrScript("Usage: ${hasOutgoingRelationship(from, to [, relType])}."),
120+
Usage.javaScript("Usage: ${{$.hasOutgoingRelationship(from, to [, relType])}}.")
119121
);
120122
}
121123

@@ -126,6 +128,24 @@ public String getShortDescription() {
126128

127129
@Override
128130
public String getLongDescription() {
129-
return "";
131+
return "returns a boolean value indicating whether **at least one** outgoing relationship exists between the given entities, with an optional qualifying relationship type. See also `incoming()`, `outgoing()`, `has_relationship()` and `has_incoming_relationship()`.";
132+
}
133+
134+
@Override
135+
public List<Example> getExamples() {
136+
return List.of(
137+
Example.structrScript("${hasOutgoingRelationship(me, page, 'OWNS')}"),
138+
Example.javaScript("${{ $.hasOutgoingRelationship($.me, $.page, 'OWNS') }}")
139+
);
140+
}
141+
142+
@Override
143+
public List<Parameter> getParameters() {
144+
145+
return List.of(
146+
Parameter.mandatory("from", "entity the relationship goes from"),
147+
Parameter.mandatory("to", "entity the relationship goes to"),
148+
Parameter.optional("relType", "type of relationship")
149+
);
130150
}
131151
}

structr-base/src/main/java/org/structr/core/function/HasRelationshipFunction.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import org.structr.common.error.FrameworkException;
2424
import org.structr.core.graph.NodeInterface;
2525
import org.structr.core.graph.RelationshipInterface;
26+
import org.structr.docs.Example;
27+
import org.structr.docs.Parameter;
2628
import org.structr.docs.Signature;
2729
import org.structr.docs.Usage;
2830
import org.structr.schema.action.ActionContext;
@@ -114,8 +116,8 @@ public Object apply(final ActionContext ctx, final Object caller, final Object[]
114116
@Override
115117
public List<Usage> getUsages() {
116118
return List.of(
117-
Usage.structrScript("Usage: ${hasRelationship(entity1, entity2 [, relType])}. Example: ${hasRelationship(me, user, 'FOLLOWS')} (ignores direction of the relationship)"),
118-
Usage.javaScript("Usage: ${{Structr.hasRelationship(entity1, entity2 [, relType])}}. Example: ${{Structr.hasRelationship(Structr.get('me'), user, 'FOLLOWS')}} (ignores direction of the relationship)")
119+
Usage.structrScript("Usage: ${hasRelationship(entity1, entity2 [, relType])}."),
120+
Usage.javaScript("Usage: ${{$.hasRelationship(entity1, entity2 [, relType])}}.")
119121
);
120122
}
121123

@@ -126,6 +128,24 @@ public String getShortDescription() {
126128

127129
@Override
128130
public String getLongDescription() {
129-
return "";
131+
return "Returns a boolean value indicating whether **at least one** relationship exists between the given entities, with an optional qualifying relationship type. See also `incoming()` and `outgoing()`.";
132+
}
133+
134+
@Override
135+
public List<Example> getExamples() {
136+
return List.of(
137+
Example.structrScript("${hasRelationship(me, page, 'OWNS')}"),
138+
Example.javaScript("${{ $.hasRelationship($.me, $.page, 'OWNS') }}")
139+
);
140+
}
141+
142+
@Override
143+
public List<Parameter> getParameters() {
144+
145+
return List.of(
146+
Parameter.mandatory("entity1", "entity that has a relationship"),
147+
Parameter.mandatory("entity2", "entity that has a relationship"),
148+
Parameter.optional("relType", "type of relationship")
149+
);
130150
}
131151
}

structr-base/src/main/java/org/structr/core/function/HashFunction.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import org.structr.common.error.ArgumentCountException;
2222
import org.structr.common.error.ArgumentNullException;
2323
import org.structr.common.error.FrameworkException;
24+
import org.structr.docs.Example;
25+
import org.structr.docs.Parameter;
2426
import org.structr.docs.Signature;
2527
import org.structr.docs.Usage;
2628
import org.structr.schema.action.ActionContext;
@@ -71,8 +73,8 @@ public Object apply(ActionContext ctx, Object caller, Object[] sources) throws F
7173
@Override
7274
public List<Usage> getUsages() {
7375
return List.of(
74-
Usage.structrScript("Usage: ${hash(algorithm, value)}. Example: ${hash(\"SHA-256\", \"test\")}"),
75-
Usage.javaScript("Usage: ${{ $.hash(algorithm, value); }}. Example: ${{ $.hash(\"SHA-256\", \"test\")}}")
76+
Usage.structrScript("Usage: ${hash(algorithm, value)}."),
77+
Usage.javaScript("Usage: ${{ $.hash(algorithm, value); }}.")
7678
);
7779
}
7880

@@ -83,7 +85,28 @@ public String getShortDescription() {
8385

8486
@Override
8587
public String getLongDescription() {
86-
return "";
88+
return """
89+
Returns the hash (as a hexadecimal string) of a given string, using the given algorithm (if available via the underlying JVM).
90+
Currently, the SUN provider makes the following hashes/digests available: MD2, MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, SHA-512/256, SHA3-224, SHA3-256, SHA3-384, SHA3-512
91+
If an algorithm does not exist, an error message with all available algorithms will be logged and a null value will be returned.
92+
""";
93+
}
94+
95+
@Override
96+
public List<Example> getExamples() {
97+
return List.of(
98+
Example.structrScript("${hash('SHA-512', 'Hello World!')}"),
99+
Example.javaScript("${{ $.hash('SHA-512', 'Hello World!') }}")
100+
);
101+
}
102+
103+
@Override
104+
public List<Parameter> getParameters() {
105+
106+
return List.of(
107+
Parameter.mandatory("algorithm", "Hash algorithm that will be used to convert the string"),
108+
Parameter.mandatory("value", "String that will be converted to hash string")
109+
);
87110
}
88111

89112
@Override

structr-base/src/main/java/org/structr/core/function/ParseDateFunction.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.structr.common.error.ArgumentCountException;
2323
import org.structr.common.error.ArgumentNullException;
2424
import org.structr.common.error.FrameworkException;
25+
import org.structr.docs.Example;
26+
import org.structr.docs.Parameter;
2527
import org.structr.docs.Signature;
2628
import org.structr.docs.Usage;
2729
import org.structr.schema.action.ActionContext;
@@ -89,8 +91,8 @@ public Object apply(final ActionContext ctx, final Object caller, final Object[]
8991
@Override
9092
public List<Usage> getUsages() {
9193
return List.of(
92-
Usage.structrScript("Usage: ${parseDate(value, pattern)}. Example: ${parseDate(\"2014-01-01\", \"yyyy-MM-dd\")}"),
93-
Usage.javaScript("Usage: ${{Structr.parseDate(value, pattern)}}. Example: ${{Structr.parseDate(\"2014-01-01\", \"yyyy-MM-dd\")}}")
94+
Usage.structrScript("Usage: ${parseDate(value, pattern)}."),
95+
Usage.javaScript("Usage: ${{ $.parseDate(value, pattern) }}.")
9496
);
9597
}
9698

@@ -101,6 +103,23 @@ public String getShortDescription() {
101103

102104
@Override
103105
public String getLongDescription() {
104-
return "";
106+
return "Parses the given string according to the given pattern and returns a date object. This method is the inverse of <a href='#date_format'>date_format()</a>.";
107+
}
108+
109+
@Override
110+
public List<Example> getExamples() {
111+
return List.of(
112+
Example.structrScript("${parseDate('2015-12-12', 'yyyy-MM-dd')}"),
113+
Example.javaScript("${{ $.parseDate('2015-12-12', 'yyyy-MM-dd') }}")
114+
);
115+
}
116+
117+
@Override
118+
public List<Parameter> getParameters() {
119+
120+
return List.of(
121+
Parameter.mandatory("string", "date string"),
122+
Parameter.mandatory("pattern", "date pattern")
123+
);
105124
}
106125
}

0 commit comments

Comments
 (0)