Consider the following initialization of hierarchical routes (excerpt from the AngularDart tutorial):
router.root
..addRoute(
name: 'add',
path: '/add',
enter: view('view/addRecipe.html'))
..addRoute(
name: 'recipe',
path: '/recipe/:recipeId',
mount: (Route route) => route
..addRoute(
name: 'view',
path: '/view',
enter: view('view/viewRecipe.html'))
..addRoute(
name: 'edit',
path: '/edit',
enter: view('view/editRecipe.html'))
..addRoute(
name: 'view_default',
defaultRoute: true,
enter: (_) =>
router.go('view', {'recipeId': ':recipeId'},
startingFrom: route, replace:true)));
While I understand that a subroute's path will be unique (being constructed from the paths of its ancestors), is the route name namespace hierarchical too or must the names be unique?
It's required that the route names are unique for all direct children of a given parent.
OK:
foo
bar
baz
qux
foo
bar
baz
Not OK:
foo
bar
bar
In general it's recommended to have unique route names throughout, for better readability, although it's not a requirement.
When referencing a route, one must specify the full path of the route foo.bar.baz from the root, or provide a relative route anchor router.go('foo', parameters: {}, startingFrom: bar)
One place where non-unique route names can cause issues is with query parameters, as query parameters are prefixed with the route name (not the full path), and can cause leaking of values between routes with the same name (/foo?foo.param1=value). That said, query parameter support is a work-in-progress, so things might change.
Related
I am using the Extension:JsonConfig on my docker instance of wikidata that has some tables loaded onto it. The configuration for the extension in my LocalSettings.php is as follows,
$wgJsonConfigEnableLuaSupport = true;
$wgJsonConfigModels['Tabular.JsonConfig'] = 'JsonConfig\JCTabularContent';
$wgJsonConfigs['Tabular.JsonConfig'] = [
'namespace' => 486,
'nsName' => 'Data',
// page name must end in ".tab", and contain at least one symbol
'pattern' => '/.\.tab$/',
'license' => 'CC0-1.0',
'isLocal' => true,
'store' => true,
];
When i query the local instance using the following url,
http://<DOMAIN_HERE>/w/api.php?action=query&list=search&srsearch=tab contentmodel:Tabular.JsonConfig &srnamespace=486&srlimit=10&format=json
i receive the following response
{"batchcomplete":"","limits":{"search":10},"query":{"searchinfo":{"totalhits":0},"search":[]}}
which means that no matches have been found even though tables that match the query statement do exist.
This same query works with commons database when the following is done
https://commons.wikimedia.org/w/api.php?action=query&list=search&srsearch=tab%20contentmodel:Tabular.JsonConfig%20&srnamespace=486&srlimit=10&format=json
Can anyone point me out as to what i am doing wrong here?
At work we have a basic Docusaurus v2 page for user documentation, and I can't share it for privacy reasons. Suffice it to say it has a sidebar which is autogenerated, where the top level contains a number of folders as categories and each category only contains .md files.
At the top level (the level of the categories) there is an empty index.md file that only exists so that the page will load. The autogenerated sidebar includes an index entry that points to a blank page. I would like to hide/get rid of this entry.
I have looked at this github discussion on something similar, but I haven't been able to make the solutions work. The sidebar.js file has the following simple contents:
module.exports = {
docs: [
{
type: 'autogenerated',
dirName: '.'
},
],
};
I have tried adding an exclude: ['path\to\index\file'] line, but this results in the error "exclude" is not allowed.
What is the proper way of hiding this index entry from the sidebar? Alternatively, is there a way to set up the site so that the index.md file is not needed at all?
I have the same setup:
/folder1
/file
/folder2
/file
index
And I wand to autogenerate the sidebar with two categories only:
folder1
folder2
Moreover, I wanted to click on the navbar and see index.
I was able to do so by:
Create a custom sidebar
function skipIndex(items) {
return items.filter(({ type, id }) => {
return type !== 'doc' || id !== 'index';
});
}
module.exports = async function sidebarItemsGenerator({ defaultSidebarItemsGenerator, ...args }) {
const sidebarItems = await defaultSidebarItemsGenerator(args);
return skipIndex(sidebarItems);
}
Then in the docusaurus.config.js
presets: [
[
'classic',
({
// https://docusaurus.io/docs/api/plugins/#docusaurus/plugin-content-docs#configuration
docs: {
sidebarItemsGenerator: require('./sidebar.js'),
},
And finally in the index.md file I must add this metadata, otherwise when I reach the index page, the sidebar disappears because the page is not included:
---
displayed_sidebar: docsSidebar
---
In the Nest js create dto I receive two properties name and age. I need to validate if user with name and age already exists should trough 400 error "duplicate values".
Like in table we have name: "John", age: 20
and we create user with the same value/combination "John" and 20, it should show error.
I tried to use validation check NameExists but do not know how to take values for both, I only take for one.
https://dev.to/avantar/custom-validation-with-database-in-nestjs-gao
#IsNotEmpty({
message: 'Name is missing',
})
#MinLength(5, {
message: 'Name is too short. Select name longer than 5 characters.',
})
#UserExists()
name: string;
#IsNotEmpty({
message: 'Age is missing.',
})
#IsInt()
#Transform(({ value }) => Number(value))
age: number;
In this example, you could see how to access other properties of the object in your custom decorator.
https://github.com/typestack/class-validator#custom-validation-decorators
However, my choice, in this case, would be to create proper unique indexes in the database and handle the DB error as you could encounter race conditions if 2 requests will come with the same user name and age at the same time.
I am trying to update a record from an html.haml form.
HTML.HAML:
%input{:name => "post[my_card_ids][]", :type => "hidden",value: "#{post["my_card_ids"]}",id: "my_card_ids"}
When I inspect the HTML page, the values are exactly like they should be.
HTML inspection:
<input id="my_card_ids" name="post[my_card_ids][]" type="hidden" value="[5d1b83a6616b6523a9020000, 5d1b9893616b653abd0b0000]">
But when I receive the same params in the controller, they become like this:
Rails Console:
<ActionController::Parameters {"my_card_ids"=>["[\"5d1b83a6616b6523a9020000\", \"5d1b9893616b653abd0b0000\"]"]
The record is being saved with all the extra paranthesis and quotation marks, because it is being passed as a string I'm guessing.
How do I pass the array cleanly, as shown in the HTML inspection and update the record?
In order to create an array in the parameters you want to create a hidden input for each value in the array:
- post["my_card_ids"].each do |card_id|
%input{ name: "post[my_card_ids][]", type: "hidden", value: card_id, id: "my_card_ids_#{card_id}" }
This works since Rack merges parameters with names ending with [] into an array. Its also how the built in FormOptionsHelper works.
You put array as string to hidden field.
Try:
%input{:name => "post[my_card_ids]", :type => "hidden",value: "#{post["my_card_ids"].join(','}",id: "my_card_ids"}
And in the controller
params[:my_card_ids].split(',')
I have a Jruby on Rails application with Neo4j.rb and a model, let's say Auth, defined like this:
class Auth < Neo4j::Rails::Model
property :uid, :type => String, :index => :exact
property :provider, :type => String, :index => :exact
property :email, :type => String, :index => :exact
end
And this code:
a = Auth.find :uid => 324, :provider => 'twitter'
# a now represents a node
a.to_json
# outputs: {"auth":{"uid": "324", "provider": "twitter", "email": "email#example.com"}}
Notice that the ID of the node is missing from the JSON representation. I have a RESTful API within my application and I need the id to perform DELETE and UPDATE actions.
I tried this to see if it works:
a.to_json :only => [:id]
But it returns an empty JSON {}.
Is there any way I can get the ID of the node in the JSON representation without rewriting the whole to_json method?
Update The same problems applies also to the to_xml method.
Thank you!
I am answering my own question. I still think that there is a better way to do this, but, for now, I am using the following hack:
In /config/initializers/neo4j_json_hack.rb I put the following code:
class Neo4j::Rails::Model
def as_json(options={})
repr = super options
repr.merge! '_nodeId' => self.id if self.persisted?
end
end
And now every JSON representations of my persisted Neo4j::Rails::Model objects have a _nodeId parameter.
The ID is typically not included because it shouldn't be exposed outside the Neo4j database. Neo4j doesn't guarantee that the ID will be identical from instance to instance, and it wouldn't surprise me if the ID changed in a distributed, enterprise installation of Neo4j.
You should create your own ID (GUID?), save it as a property on the node, index it, and use that to reference your nodes. Don't expose the Neo4j ID to your users or application, and definitely don't rely on it beyond a single request (e.g. don't save a reference to it in another database or use it to test for equality).