How to create history data in pinia [closed] - vue.js

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 months ago.
Improve this question
I am using pinia in my project and I have two array states. Now I need to have the history of the entered data in these states.
For example: every time I push an object to array in state or change the data in an array, I want to be able to push the data of that array in an array in store.
The problem is that by pushing current data of the state in an array in another store, in in all indexes of the new areay, the new value of the first state will be replaced and I can't have the history of changes
The point is that in the first store, pinia's default settings must be available so I can use the features, but in the second store I need the data to be unchanging and only added to array.
Let me also add that for the second store there is no need for using pinia and I would be glad if you could suggest something else. (But whatever feature I use, by changing the state in the first store, my data changes)

Maybe VueUse is the correct pick here.
Have you tried using (heh) useRefHistory? That does exactly what you need: a history of your reactive values.
Recall that you can use storeToRefs to get this done.

Store values need to be watched and accumulated, e.g. with watch:
watch(
() => store.myData,
(data, oldData) => {
if (!isEqualDeep(data, oldData)
store.myDataHistory.push(cloneDeep(data)) // should preferably be inside an action
},
{ deep: true }
);

Related

I'm tiring to create a new user in Moodle using auth_email_signup_user but I'm not sure how to format the request [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I have a few required custom profile fields that are date pickers and checkboxes. and I'm not sure what type to put them as in the request the only example the documentation has is one with type string. I keep getting the response
{
"exception": "invalid_parameter_exception",
"errorcode": "invalidparameter",
"message": "Invalid parameter value detected",
"debuginfo": ""
}
this is my request below:
https://example.com/webservice/rest/server.php?wstoken=faketoken&wsfunction=auth_email_signup_user&moodlewsrestformat=json&username=fromapp&password=FakePass123&firstname=From&lastname=App&email=fake#mailinator.com&customprofilefields[0][type]=text&customprofilefields[0][name]=profile_field_Church&customprofilefields[0][value]=JesusYouth&customprofilefields[1][type]=date&customprofilefields[1][name]=profile_field_DOB&customprofilefields[1][value]=2014-06-19&customprofilefields[2][type]=checkbox&customprofilefields[2][name]=profile_field_Saved&customprofilefields[2][value]=1&customprofilefields[3][type]=text&customprofilefields[3][name]=profile_field_Sex&customprofilefields[3][value]=Male&customprofilefields[4][type]=text&customprofilefields[4][name]=profile_field_phone_no&customprofilefields[4][value]=1-868-479-8661&customprofilefields[5][type]=text&customprofilefields[5][name]=profile_field_Marital&customprofilefields[5][value]=Single
I'm not sure what I need to do to make this request work and the documentation doesn't give much insight or I just haven't found it
So after playing around with the request on postman what I discovered is that the only type you need to use is string. I also discovered that for date fields the value must be unixtime and for checkboxes the value must be either 0 or 1.
https://example.com/webservice/rest/server.php?wstoken=faketoken&wsfunction=auth_email_signup_user&moodlewsrestformat=json&username=formapp7&password=fakepassword&firstname=From7&lastname=App7&email=fake#mailinator.com&customprofilefields[0][type]=string&customprofilefields[0][name]=profile_field_church&customprofilefields[0][value]=JesusYouth&customprofilefields[1][type]=string&customprofilefields[1][name]=profile_field_saved&customprofilefields[1][value]=Yes&customprofilefields[2][type]=string&customprofilefields[2][name]=profile_field_man&customprofilefields[2][value]=0&customprofilefields[3][type]=string&customprofilefields[3][name]=profile_field_born&customprofilefields[3][value]=1630813061&customprofilefields[4][type]=string&customprofilefields[4][name]=profile_field_single&customprofilefields[4][value]=Single&customprofilefields[5][type]=string&customprofilefields[5][name]=profile_field_aboutyou&customprofilefields[5][value]=Well i am new
This is an example of how a request would look where profile_field_man is a checkbox and profile_field_born is a date field. something also worth noting is that 'born' is the short name of the profile field mentioned before and the words 'profile_field_' must be prepended to it. I hope this helps anyone trying to use auth_email_signup_user

HandsOnTable (Vue Wrapper) - Associate row with database id?

I'm trialling HandsOnTable via the Vue wrapper to make a simple database editor. I can populate the table easily, however I now need to save changes back to the database.
If I use the afterChange() method hot will give me the changes in the cells that have changed, however I need to be able to associate those changes with a database id to send them back to the server. Any idea of how to do this, and also is it possible to get the changes associated with a row? Would it also be possible to do this without displaying the database id to the user in the table?
To answer your main question, you can associate metadatas to cells. So you can put your technical id in your first column for example or a hidden column (or whereever you want).
hot.setCellMeta(0, 0, 'myIdName', 'myIdValue');
where "hot" is your Handsontable instance. (documentation reference)
You can then access getCellMeta(0, 0).
Second question :
and also is it possible to get the changes associated with a row ?
You already are able to get the changes of specific rows by filter the changes in the afterChange hook. Taking the example from Handsontable documentation this is how you get the row :
new Handsontable(element, {
afterChange: (changes) => {
changes.forEach(([row, prop, oldValue, newValue]) => {
// Some logic...
});
}
})
As you can see changes is an array of change that contain row and col (prop).
Hope this helps.

Iterating store in relay optimisticUpdater

Apologies in advance, I'm new to relay and not sure I've got all the terminology here right...
I have a (simplified) graph that looks like:
customer {
summary(id: "ABC123") {
records { // This is an array of Record
tag
}
}
}
Customer, Summary and Record are all objects with global IDs - they show up as records in the Relay DevTools inspector.
I have a mutation that removes a tag by name (from elsewhere in the graph - not shown), from which I need to update the customer summary object to remove the record with associated tag. I have tried two approaches and not gotten very far with either:
Re-request customer.summary as part of the mutation. The problem is I don't know what the ID is at that point. (Maybe I can thread it through some how, but that would be messy.) Also doesn't really solve the problem, since I'd like to do this optimistically.
In an optimistic updater, remove any tag record that matches. This seems like it should work, but the RecordProxy doesn't appear to have a rich enough API to enable me to do this.
First approach, I can't seem to get access to the summary record via the root:
const customer = store.getRoot().getLinkedRecord('customer') // works!
customer.getLinkedRecord("summary") // undefined
customer.getLinkedRecord("summary", {id: "ABC123"}) // undefined
Second approach, if I could ask the store for "all records of type" or even "all records" I could iterate through and find the one I need to edit, but this doesn't seem to be a method that's exposed (even though Relay DevTools must be doing it somehow).

Accessing Vue Store values in Router

I need to access a variable from my store in my router. This variable is called 'isAdmin'. Now, when I'm using the following code, I'm getting the initial state (which has the value of 'false'):
console.log(store.state.isAdmin)
Although I've updated the 'isAdmin' value to 'true' committing an action, the state of 'isAdmin' continues to be as the initial state.
Now, if I console.log the following object:
console.log(store.state)
I see this:
My question is: How do I get to the value of isAdmin after I've amended it in my store?
Thank you!!!

Google Rest api to get primary mail [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How to get the gmail primary mail using Google rest API.Currently i am using the GET https://www.googleapis.com/gmail/v1/users/userId/messages Rest API but that will give the social and promotion mail.I am referring this site:https://developers.google.com/gmail/api/v1/reference/users/messages/list
Try adding this as a filter in your query when calling messages.list
[ in:inbox -category:{social promotions updates forums} ]
that only gives you the good stuff. It's basically saying give me everything in the inbox apart from social, promotions, updates and forums.
Or in my inbox I also seem to have updates so you'd change to
[ in:inbox -category:{social promotions forums} ]
Cheers
John
Its pretty straight forward actually
We can query the messages by using labels. Labels are of two types System labels and User Labels.
For primary we can use System label called "INBOX" and get the emails that belong to that category. There are other system labels like CATEGORY_PROMOTIONS, CATEGORY_SOCIAL etc.
You can use the Try It! feature with Google to test it out.
Get labels:
https://developers.google.com/gmail/api/v1/reference/users/labels/list
For a given label, say INBOX in your case query the messages
https://developers.google.com/gmail/api/v1/reference/users/messages/list
You can also get the STARRED, CATEGORY_PERSONAL for starred and important emails from the inbox.
Edited for sample code.
Java Code Sample available within the link, but a snippet here:
public static void listLabels(Gmail service, String userId) throws IOException {
ListLabelsResponse response = service.users().labels().list(userId).execute();
List<Label> labels = response.getLabels();
for (Label label : labels) {
System.out.println(label.toPrettyString());
}
}