I can not reach all data in json file as Strapi backend? - strapi

**https://admin.medicte.ca/Doctors
**https://admin.medicte.ca/Doctors?doctorName_contains=tuysuz
As you can see here, there are two different urls which are strapi json files. The problem here is when I click first link there is only 100 doctor. In CMS. admin panel I can see 143 doctor. If I search by name like in the second url. There is that doctor, which it doesn't appear on the first link. Any solution?

This is called pagination.
If the size of your collection exceeds the page size, simply ask for the next page: https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/sort-pagination.html or you can also change the limit in config/api.js with
// path: ./config/api.js
module.exports = ({ env }) => ({
rest: {
defaultLimit: 100,
maxLimit: 250,
},
});

Related

How can I disable and enable a resource route Link in remix-run

Is there a way to disable a Resource route link while the resource is being generated and enabling it after that?
I have a PDF report that gets generated as soon as the user clicks on a Link. So I'm using a resource route that returns the PDF as a ReadableStream with a content-Disposition of attachment.
Here's a a code fragment example:
export const loader: LoaderFunction = async ({ params }) => {
invariant(params.recordID, "Record Id is required!");
let recordID = params.recordID;
let reportsService = createReportsService();
let reportFileStream = await reportsService.getReport(
recordID
);
return new Response(reportFileStream, {
headers: {
"Content-disposition": `attachment; filename=report.pdf`,
"Content-Type": "application/pdf",
},
});
};
I'm using the Link to the resource route this way:
<Link to={reportUrl} reloadDocument >
Get the Report
</Link>
I want the Link to get disabled as soon as the user clicks on it and then re enable it after the report is ready and the user has saved it (or discarded the "save" window).
I can't use useTransition hook because reloadDocument disables javascript behavior but I can't find out another way to disable and enable the link.
I can only disable it as soon as the user clicks on it (with a conditional pointer-events style controlled by useState) but I haven't found a way to detect when the report has been generated and the user has saved it (or discarded the "save" window) so I can re enable the link again.
So any help or hint to find a solution is very much appreciated!

Create a non-editable field in Strapi

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!

how can i use the same page as an edit and an add and cache them offline with simple url change as in description

hi there so i have a link lets say it is https://example.com/exp
the exp page is my add page and it is cached in my service worker and works offline
now when i open my list and choose to edit a record it opens in https://example.com/exp?id=2
when i open this page it doesn't work offline if i remove the id part then it works but then it is an add i want my edit page to be offline as-well
how do i fix this?
please help
my code**
// give your cache a name
const cacheName = 'my-cache';
// alert('hi')
// put the static assets and routes you want to cache here
const filesToCache = [
'/',
'https://example.com/exp',
];
// the event handler for the activate event
self.addEventListener('activate', e => self.clients.claim());
// the event handler for the install event
// typically used to cache assets
self.addEventListener('install', e => {
e.waitUntil(
caches.open(cacheName)
.then(cache => cache.addAll(filesToCache))
);
});
// the fetch event handler, to intercept requests and serve all
// static assets from the cache
self.addEventListener('fetch', e => {
e.respondWith(
caches.match(e.request)
.then(response => response ? response : fetch(e.request))
)
});
okay so cache and serviceworkers
website can only work offline with the exact link. Change it a bit and it brakes
you have to cache the id if you want to cache a edit view
you have to also use something like Dexie/indexedDB for an offline data/storage handler
and then based on your data you fetch you have to for loop the ids and stringify them with your url and then add them - i have the code to show how it works
if anyone wants it

Inertia: Reload page with updated data without modifying scroll position

I'm using Inertia/Laravel/VueJs. I have a page with many posts and each post can be marked as completed. When a post is marked as completed on the front-end I have a v-bind which toggles a CSS class which should be applied to completed tasks.
The behaviour I would like is: a user scrolls down a page, clicks the completed button, and the back-end sends that newly updated data to the front-end, making the v-bind true, causing the CSS class to be applied without jumping to the top of the page.
With the code below I can click the completed button, and it is updated in the database, but that new data isn't sent to the front-end.
Controller:
public function markAsCompleted(Request $request)
{
$post = Post::find($request->id);
$post->completed = true;
$post->save();
return Redirect::route('posts');
}
Javascript function called at click of completed button:
completed(id) {
this.completedForm.put(`/endpoint/completed/${id}`, {
preserveScroll: true
});
},
If I change the Javascript function to:
completed(id) {
this.completedForm.put(`/endpoint/completed/${id}`, {
preserveScroll: true,
onSuccess: () => {
Inertia.get('posts');
},
});
},
In this case, the new data is returned to the front-end with the post being marked as completed, but the preserveScroll doesn't work, and jumps the user to the top of the page.
Any ideas on how to get my desired use case working? Users could have hundreds of posts so I can't have the page jump up to the top every time.
Thank you for any help!
To update your app while preserving the state:
Inertia.get('posts', params, {
preserveState: true,
})
One way, not the cleanest, but it is a solution. Just click "Completed Button" to send a request to the backend, and ONLY to check if the response is success, then update that task in frontend as complete. So you just update (add class) this element and you don't rerender whole DOM. Because, if you get success response, thats done in the backend for sure.

How to access quantityInStock on a dynamic page in Wix

So I'm using Wix to create a ecommerce store, however the standard store isn't flexible enough for me.
I have a dynamic product page and I want to access product quantity in stock with code in order to show whether the product is in stock or not.
I fount this in the documentation (Link)
$w('#myProductPage').getProduct()
.then( (product) => {
let productName = product.name;
let productDescription = product.description;
// see example product object below
} )
.catch( (error) => {
console.log(error);
} );
The only thing is that I don't know whats the page name with what i have to replace '#myProductPage'.
As far as I understand it I have to replace it with my slug product page name however I don't know where I could see it - it should be named products-2 but that doesn't work, it shows an error that the name is not a valid selector.
I haven't found basically any example codes for Wix Corvid and that's why I'm reaaally struggling with such a small thing.
With $w(), you want to pass in the page element's ID -> $w('#elementID')
The element ID can be found in the property pane on the page. Select the page element, right click > View Properties. This will give you the ID you want to pass in to the function. Think of it like a document.getElementById() function replacement.

Resources