How to do mandatory fields in prismic.io CMS? - reactjs

I'm using Prismic.io as a headless CMS and bringing content into my React front end. How do I set up a content type so that fields are mandatory?
Here's what I have so far...
{
"Main" : {
"uid" : {
"type" : "UID",
"config" : {
"placeholder" : "UID"
}
},
"image" : {
"type" : "Image"
},
"title" : {
"type" : "StructuredText",
"config" : {
"single" : "heading1",
"placeholder" : "Title..."
}
},
"description" : {
"type" : "StructuredText",
"config" : {
"multi" : "paragraph,em,strong,hyperlink",
"placeholder" : "Description..."
}
}
}
}

as for now, prismic.io CMS doesn't allow required fields. The only required field is the native "UID" field. They recommend using the in-website preview for publishers to preview the result before shipping content rather than adding constraints in the editor.

Related

Found $id field without a $ref before it, which is invalid

I have this kind of documents in my mongodb (3.4):
{
"_id" : ObjectId("588e7a5951fa0982213c8f72"),
"content" : "This is example"
"createdBy" : ObjectId("5867822e10031569325c87b4"),
"title" : "Notifications",
"community" : NumberLong(7),
"updatedAt" : ISODate("2018-10-18T22:10:37.795Z"),
"tags" : [
null,
{
"type" : "question",
"$ref" : "tag",
"$id" : ObjectId("588e7a5951fa0982213c8f73"),
"$db" : "forum"
},
{
"$id" : ObjectId("588e7a5951fa0982213c8f74"),
"$db" : "forum",
"type" : "question",
"$ref" : "tag"
}
],
"status" : "opened",
"pinned" : false
}
I want to remove null from tags array, so I tried this query:
db.getCollection('question').update(
{ _id : ObjectId("588e7a5951fa0982213c8f72") },
{ $pullAll: { tags: [null] } },
{ multi: true }
)
But, I got this error:
Found $id field without a $ref before it, which is invalid.
[Edit]
I found that $id and $ref is out of sequence in the third record of the tags field. So, can I fix the sequence and remove null using update query?

mongodb - extract a particular value in an embedded array within an array

I'm fairly new to mongoDB, but I've managed to archive a load of documents into a new collection called documents_archived in the following format using an aggregation pipeleine:
{
"_id" : ObjectId("5a0046ef2039404645a42f52"),
"archive" : [
{
"_id" : ObjectId("54e60f49e4b097cc823afe8c"),
"_class" : "xxxxxxxxxxxxx",
"fields" : [
{
"key" : "Agreement Number",
"value" : "1002465507"
}
{
"key" : "Name",
"value" : "xxxxxxxx"
}
{
"key" : "Reg No",
"value" : "xxxxxxx"
}
{
"key" : "Surname",
"value" : "xxxxxxxx"
}
{
"key" : "Workflow Id",
"value" : "xxxxxxxx"
}
],
"fileName" : "Audit_C1002465507.txt",
"type" : "Workflow Audit",
"fileSize" : NumberLong(404),
"document" : BinData(0, "xxxxx"),
"creationDate" : ISODate("2009-09-25T00:00:00.000+0000"),
"lastModificationDate" : ISODate("2015-02-19T16:28:57.016+0000"),
"expiryDate" : ISODate("2018-09-25T00:00:00.000+0000")
}
]
}
Now, I'm trying to extract just the Agreement Number's value. However, I have tried many things that my limited knowledge, searching and documentation will allow. Wondered if the mongoDB experts out there can help. Thank you.
Here's a solution that uses the agg framework. I am assuming that each doc can have more than one entry in the archive field but only one Agreement Number in the fields array because your design appears to be key/value. If multiple Agreement Numbers show up in the fields array we'll have to add an additional $unwind but for the moment, this should work:
db.foo.aggregate([
{$unwind: "$archive"}
,{$project: {x: {$filter: {
input: "$archive.fields",
as: "z",
cond: {$eq: [ "$$z.key", "Agreement Number" ]}
}}
}}
,{$project: {_id:false, val: {$arrayElemAt: ["$x.value",0]} }}
]);
{ "val" : "1002465507" }
You can use following in mongo shell to extract only values:
db.documents_archived.find().forEach(function(doc) {
doc.archive[0].fields.forEach(function(field) {
if (field.key == "Agreement Number") {
print(field.value)
}
})
})

firebase query by array of child

I have this document structure
{
"parking" : {
"-Kace9LLJBuhG1RBWsy2" : {
"address" : "avenida",
"company_name" : "Company",
"hours" : 40,
"owner" : "Fmex7wiYAsbxNFhDy39X1r28J9L2",
"receipts" : [
{
"id" : "-KbB-0Wxxx_vsCxy",
"date" : "3/01/2017",
"user_id" : "Fmex7wiYAsbxNFhDy39X1r28J9L2",
"value" : 50
},
{
"id" : "-KbB-0Wzzzz_vsCy",
"date" : "3/30/2017",
"user_id" : "Fmex7wiYAsbxNFhDy39X1r28J9L2",
"value" : 50
}
],
"social_name" : "Company",
"value" : "50"
},
Is it possible for me to pick up a parking lot, using the id of a receipt?
Example: I want to show the user a parking only if the user ID is inside the receipts array
Or do not you want to do this with the firebase and I would have to create a reference instead of a subdocument?
EDIT
I've tried something like:
var refParkingByUser = firebase.database().ref('parking').orderByChild('receipts').equalTo(Auth.$getAuth().uid);
But how do I access the receipt elements?
As Frank mentioned you can't do that with your data. If you add in another node that looks like this:
{
"recieptParkingLots": {
"-KbB-0Wxxx_vsCxy": {
"-Kace9LLJBuhG1RBWsy2": true
},
"-KbB-0Wzzzz_vsCy": {
"-Kace9LLJBuhG1RBWsy2": true
}
}
}
You'd easily be able to find which parking lots a receipt is attached too.
If you can only have one receipt per parking lot I'd store them outside the parking lot node:
{
"parking" : {
"-Kace9LLJBuhG1RBWsy2" : {
"address" : "avenida",
"company_name" : "Company",
"hours" : 40,
"owner" : "Fmex7wiYAsbxNFhDy39X1r28J9L2",
"receipts" : {
"-KbB-0Wxxx_vsCxy" : true,
"-KbB-0Wzzzz_vsCy" : true
}
"social_name" : "Company",
"value" : "50"
},
}
"receipts" : {
"-KbB-0Wxxx_vsCxy" : {
"parking" : "-Kace9LLJBuhG1RBWsy2",
"date" : "3/01/2017",
"user_id" : "Fmex7wiYAsbxNFhDy39X1r28J9L2",
"value" : 50
},
"-KbB-0Wzzzz_vsCy" : {
"parking" : "-Kace9LLJBuhG1RBWsy2",
"date" : "3/30/2017",
"user_id" : "Fmex7wiYAsbxNFhDy39X1r28J9L2",
"value" : 50
}
}
}
Then you can easily look up the parking lot and then go and get the receipt.

Parsing JSON array in Swift 3

I'm trying to parse JSON file to show in table view in Swift 3 without using external frameworks, but my knowledge in Swift is not enough. I have looked other questions, but nothing worked for me. The problem is that in my JSON there are couple of nested arrays.
Here is example of the JSON file:
"guides" : [
{
"name" : "First Guide",
"sections" : [
{
"title" : "Controls",
"data" : [
{
"value" : "controls.PNG",
"type" : "image"
},
{
"value" : "Sensitivity: Changes the sensitivity of the camera when turning.",
"type" : "text"
},
{
"value" : "Invert Y-Axis: Toggles inversion of camera when looking up/down.",
"type" : "text"
},
{
"value" : "crosshair.PNG",
"type" : "image"
},
{
"value" : "Lefty : Toggles the D-pad being on the left/right side of the screen.",
"type" : "text"
},
{
"value" : "Swap Jump and Sneak : Chooses whether to swap the position of jump and sneak buttons.",
"type" : "text"
},
{
"value" : "Button size - Changes the size of the buttons. Smaller buttons allow extra slots for the hotbar.",
"type" : "text"
}
]
},
{
"title" : "User Profile",
"data" : [
{
"value" : "profile.png",
"type" : "image"
},
{
"value" : "Use Cellular Data: Gives the Player the option to use cellular data.",
"type" : "text"
}
]
},
{
"title" : "Global Resources",
"data" : [
{
"value" : "resources.png",
"type" : "image"
},
..............
How I get parse the data into Swift arrays and use it to be displayed in UITableView controller. There are couple of "guides" in this JSON and I need to be able to show only one of them at the time.
Help will be much appreciated. Thank you in advance.
Try using following code:
let jsonString = "[\"a\",\"b\"]"
let jsonData = jsonString.data(using: .utf8)! as Data
do {
let dataJson = try JSONSerialization.jsonObject(with: jsonData, options: .mutableContainers)
print(dataJson)
}
catch {
print("error getting xml string: \(error)")
}

Why is my API not showing up on deployment?

I suspect this is caused by the following bug in Endpoints (if valid) but I'm also sure there's a workaround somewhere.
https://code.google.com/p/googleappengine/issues/detail?id=9050&can=4&colspec=ID%20Type%20Component%20Status%20Stars%20Summary%20Language%20Priority%20Owner%20Log
Steps to reproduce:
Change a method name, API name of a method, or parameter list in an Endpoints class.
Run the endpoints.sh script to generate the API files.
Inspect the API files locally and witness the changes being there. So far so good.
Deploy to the default version of the app on the server.
Check the logs for the call to /_ah/spi/BackendService.getApiConfigs. There are no errors!
Go to API Explorer and clear the browser cache. Inspect the API. The change is not there.
Request the API file directly in the browser, eg. https://[app-id].appspot.com/_ah/api/discovery/v1/apis/[api-name]/v1/rpc The change is not there.
Frustrated with the above, I decided to start completely from scratch on a new app ID. I still see no API in the API Explorer and get a 404 on the URL in step 7 above!
Here's my endpoint class:
#Api(name = "ditto", version = "v1")
public class CategoryEndpoint extends BaseEndpoint {
#SuppressWarnings("unused")
private static final Logger log = Logger.getLogger(CategoryEndpoint.class.getName());
#ApiMethod(name = "category.list")
public WireCategory list() {
Category root = categoryDao.getRoot();
WireCategory wireRootCategory = new WireCategory(root);
return wireRootCategory;
}
}
And here's the generated .api file:
{
"extends" : "thirdParty.api",
"abstract" : false,
"root" : "https://1.eliot-dev-uk-ditto-do.appspot.com/_ah/api",
"name" : "ditto",
"version" : "v1",
"defaultVersion" : false,
"adapter" : {
"bns" : "https://1.eliot-dev-uk-ditto-do.appspot.com/_ah/spi",
"deadline" : 10.0,
"type" : "lily"
},
"auth" : {
"allowCookieAuth" : false
},
"frontendLimits" : {
"unregisteredUserQps" : -1,
"unregisteredQps" : -1,
"unregisteredDaily" : -1,
"rules" : [ ]
},
"cacheControl" : {
"type" : "no-cache",
"maxAge" : 0
},
"methods" : {
"ditto.category.list" : {
"path" : "list",
"httpMethod" : "GET",
"scopes" : [ ],
"audiences" : [ ],
"clientIds" : [ ],
"rosyMethod" : "ditto.api.CategoryEndpoint.list",
"request" : {
"body" : "empty"
},
"response" : {
"body" : "autoTemplate(backendResponse)"
}
}
},
"descriptor" : {
"schemas" : {
"WireCategory" : {
"id" : "WireCategory",
"type" : "object",
"properties" : {
"webSafePath" : {
"type" : "string"
},
"prettyPath" : {
"type" : "string"
},
"children" : {
"type" : "array",
"items" : {
"$ref" : "WireCategory"
}
},
"path" : {
"type" : "array",
"items" : {
"type" : "string"
}
},
"name" : {
"type" : "string"
},
"id" : {
"type" : "string",
"format" : "int64"
}
}
}
},
"methods" : {
"ditto.api.CategoryEndpoint.list" : {
"response" : {
"$ref" : "WireCategory"
}
}
}
}
}
This URL gives me a 404 where I expect to see my API JSON:
https://eliot-dev-uk-ditto-do.appspot.com/_ah/api/discovery/v1/apis/ditto/v1
This is killing me!
EDIT:
Here's a diff I just spotted between the .api file generated by App Engine 1.7.5 and 1.7.6. Not sure why the URLs have changed.
ditto-v1.api from 1.7.6:
{
"extends" : "thirdParty.api",
"abstract" : false,
"root" : "https://1.eliot-dev-uk-ditto-do.appspot.com/_ah/api",
"name" : "ditto",
"version" : "v1",
"defaultVersion" : false,
"adapter" : {
"bns" : "https://1.eliot-dev-uk-ditto-do.appspot.com/_ah/spi",
"deadline" : 10.0,
"type" : "lily"
}
...
ditto-v1.api from 1.7.5:
{
"extends" : "thirdParty.api",
"abstract" : false,
"root" : "https://eliot-dev-uk-ditto-do.appspot.com/_ah/api",
"name" : "ditto",
"version" : "v1",
"defaultVersion" : false,
"adapter" : {
"bns" : "http://eliot-dev-uk-ditto-do.appspot.com/_ah/spi",
"deadline" : 10.0,
"type" : "lily"
}
...
As you already pointed out, it was due to an weird issue in SDK 1.7.6, which adds that 1. at the beginning of the endpoint root url in the .api files...
I've tried the new SDK 1.7.7 and it seems to be solved...

Resources