The doc and its all fields are expanded by default, but I need it to be shrunk because it's huge. I couldn't find a setting in settings. (although I found the dark mode which is cool)
If you're talking about the Dev Tools tab:
Then afaik, the only thing to do is to limit the fields you're fetching.
ex.
GET /_search
{
"_source": "obj.*",
"query" : {
"term" : { "user" : "kimchy" }
}
}
ref --> Elasticsearch Page
But, if you're talking about the Discover tab, then you just need to press on the + on the fields on the left side to show only the selected ones.
hope that answers your question.
Related
I have a project that sells products.
A product can have a price and optional: new_price. I would like to be able to sort them by price/new_price combined, meaning that I would need an additional entry in the DB like "final_price". I got an idea to create a non-editable field "new_price" in Content-Type Builder/schema.json and then update that with the final price for the product on "beforeCreate" in the lifecycles.js. However, I am not sure Strapi allows that, as I haven't been able to find a resource pointing in the documentation that it can. If there is a hacky way to do it, please advise. I am open to all kinds of other suggestions on how to do this Business logic as well.
Thank you in advance.
There is a way in strapi to make the field non editable on UI. You can go to Content-type-builder-> Your component-> Configure the view. And click on the text field. You can just make editable field as false.
I see two options:
(a) Add the field and forget about it being non-editable. You can calculate the final_price on insertion of an entry in your collection with Lifecycle hooks: https://docs.strapi.io/developer-docs/latest/development/backend-customization/models.html#lifecycle-hooks.
(b) Don't add a new field, but override the controller to return an additional field: https://docs.strapi.io/developer-docs/latest/development/backend-customization/controllers.html#extending-core-controllers.
Ok, so I found a "hacky" way to do this. I don't like it, as it is not that beautiful and sophisticated, but it does the job.
In product schema.json I added a
"final_price": {
"type": "decimal"
}
In lifecycles.js, I created a new function that will calculate my final price and write it in "final_price" attribute:
module.exports = {
beforeCreate(event) {
priceCalc(event);
},
beforeUpdate(event) {
priceCalc(event);
},
};
const priceCalc = (event) => {
const { data } = event.params;
data.final_price = data.new_price ? data.new_price : data.price;
};
In the admin panel, in Content-Type Builder in Product, I clicked "Configure the view" and deleted the Final Price field from Displayed Fields section. This made the field hidden, lol.
Now I am sorting all products with sort: ['final_price:asc']
That is it.Hope it helps anyone!
Has anyone done anything with AngularJS and select droplists populating another droplist on the page based on a selection.
We have a service we are populating a Select droplist with. But we have another droplist on the page that, when the first droplist's section is made, the second droplist will dynamically populate with information based on the selection of the first droplist.
JSON structure example:
[{
"Cars":{
"Type": "Hatchback",
"Type": "Sedan"
},
"Trucks":{
"Type": "Small",
"Type": "Full Size"
}
}]
So if my first <select> droplist contains options for Cars and Trucks, then based on that selection the second <select>droplist will dynamically populate with the 'Type' based on the selection of a Car or Truck.
Does anyone have any insight or point me to any tutorials based on this?
Thanks in advance
Use the option in you first selection to populate the list:
<select ng-model="d1" ng-options="key for key in vehKeys"></select>
<select ng-model="d2" ng-options="t.Type for t in veh[d1]"></select>
my controller looks like this:(I changed your format, as it was, Type would just keep overwriting its self)
$scope.veh = {
"Cars":[
{"Type": "Hatchback"},
{"Type": "Sedan"}
],
"Trucks":[
{"Type": "Small"},
{"Type": "Full Size"}
]
};
$scope.vehKeys = Object.keys($scope.veh);
I'm not entirely sure why you cannot do something like this though
<select ng-model="d1" ng-options="type for type in Object.keys(veh)"></select>
so I just did it in the controller.
Im not sure if Im missing something here.. but when I create a new data-type called Single Media Picker in umbraco 7 and uses the new Media Picker-property editor and keep the "multiple selections option" unchecked.. I am still able to select multiple images in the media picker-dialog..and once selected.. they all show up in my property-filed as well.. any ideas of why?.. guess its a bug in Umbraco.. and if thats the case.. anyone have a clue of how to limit the media-picker to a single selection for my own custom property editor?
Thanks in advance!
It depends a bit on how you use the media picker in your custom property editor. We're using the media picker in a completely separate tree for which we generate the JSON that yields the editor ourselves.
The property data that generates a single item picker looks a bit like this:
{
"label" : "Some Image",
"description" : "423 x 258px",
"view" : "mediapicker",
"config" : {
"multiPicker" : "0"
},
"hideLabel" : false,
"id" : 4,
"value" : "1092",
"alias" : "imageIdProperty"
}
Notice the config section. You could try to inspect the data that goes to the client and see what JSON is used to generate your picker.
I'm making an extension to customize Google' homepage background.So I write some match rules in manifest like this:
"content_scripts": [
{
"matches": ["https://www.google.com/", "http://www.google.com/"],
"js": ["static/js/jquery.js", "static/js/contentscript.js"]
}
],
and some scripts in contentscript.js:
var imgURL = chrome.extension.getURL("static/images/bg.jpg");
$('body').css('background-image', 'url(' + imgURL + ')');
The script works fine for https://www.google.com, but when I try to search something ,the page jumps to https://www.google.com/#newwindow=1&sclient=psy-ab&q=Google&oq=Google&gs_l=hp.3..35i39l2j0i20l2j0l6.4788.5717.2.5939.5.3.2.0.0.0.142.397.0j3.3.0....0.0..1c.1.20.hp.xCFVga8gVZU&bav=on.2,or.r_cp.r_qf.&bvm=bv.49784469%2Cd.dGI%2Cpv.xjs.s.en_US.MpiVkF51mpA.O&fp=806ba48f5b2ed550&biw=1920&bih=963
But the script is still working after the jumping! And if I paste the long url in a new tab directly, it won't work!
I think it should be related with iframe or Ajax or something else. Could someone give some more details? And how can I prevent scripts from running after the url changed?
If you want to apply a style to Google's home page, just use a selector which is very specific to Google's homepage. With the Inspector, I quickly discovered that the <body> tag at the homepage has a class "hp". This class does not show up in search results.
Drop your JavaScript code, and use
Part of manifest.json
"content_scripts": [
{
"matches": ["*://www.google.com/*"],
"css": ["my-google-style.css"]
}
],
"web_accessible_resources": [
"static/images/bg.jpg"
],
The first wildcard, *, means "http" and "https".
The added wildcard at the end does not matter, because the "homepage" requirement is enforced in the next stylesheet.
The "web_accessible_resources" key is necessary if you want to display the image in an external (=non-extension) page.
my-google-style.css
body.hp {
background-image: url("chrome-extension://__MSG_##extension_id__/static/images/bg.jpg");
}
The first part of my answer is the recommendation for your case. In general, if you want to catch every (scripted and user-initiated) URL change, including but not limited to:
history.pushState / history.replaceState
location.hash = '...';
User goes back / forward (and changes hash / history state)
... then you need to use the chrome.webNavigation API in the background/event page, in particular the onHistoryStateUpdated and/or onReferenceFragmentUpdated events. In response to these events, you'll either send a message or execute a content script.
If you only expect rewrites of the reference fragment (aka location hash), then there's no need for the webNavigation API. The implementation will be simplier, as you only need to listen to the global hashchange event in the content script.
You need to include a wildcard * to your matches like so:
"content_scripts": [
{
"matches": ["https://www.google.com/*", "http://www.google.com/*"],
"js": ["static/js/jquery.js", "static/js/contentscript.js"]
}
],
I was looking for a solution that
displayed multiple columns of independent data
did not require a click (or focus) to show the list
had a simple interface
supported visible & hidden values (like HTML's <select>)
has color highlighting to show matches
automatically deletes character entries that are not in any of the choices
I wasn't able to find a control that met these requirements, so I created one. Here is an image of the control in use.
The code to create this control is:
$('input#scrolltest').menuoptions({
"Data": { 1:"January",2:"February",3:"March",4:"April",5:"May", 6:"June",7:"July",
8:"August",9:"September",10:"October",11:"November",12:"December" },
"onSelect": function(mo, data) {
console.log(mo, data.newVal, data.type );
},
"InitialValue": { 'val': 'December'},
"Height": 200,
"Sort": []
});
This control is documented here
The above example is part of this demo page