Hello! I need help urgently. How can I add data to a collection in another collection? From the scheme presented below, I want to demonstrate my problem. On the page of my site there are windows № 1,2, the data of which displays data from the collection №1. On the same page, there is a window No. 3,4 for entering data into the collection No. 2. This data is entered manually, this is the date and quantity. Direct arrows indicate the connections, and the curved arrows indicate the direction in which the data should be saved.
The problem is that I can not save all the data in one collection because I can not save the data connected to another collection by clicking on the save button. And I need that in the collection number 2 were brought simultaneously all the data displayed in the field number 1,2,3,4. I will be grateful for any help, thanks !!!
![](https://static.wixstatic.com/media/a27d24_9cf9865c166b4fa2bc8519f6b921d73b~mv2.png/v1/fill/w_794,h_522,al_c,q_90,enc_auto/a27d24_9cf9865c166b4fa2bc8519f6b921d73b~mv2.png)
Hello Heson Li
If not difficult, can you see this topic?
https://www.wix.com/code/home/forum/questions-answers/help-in-scheduling-for-pupils
I tried to do this through reference. But when a client comes to his page, he sees all the students and not only his child.
Approximately like this should look like a schedule on the client page
Next to the student's home, there must be lessons learned. Ie what subjects and how much passed the student and when.
If there are suddenly any thoughts about this, I will be grateful for any help
Your welcome
Hello dear Heson !!!
I did very well, the code works great. Very much to you for the help !!! You for one moment did something on what I worked for a whole month :)
If you are not averse, and my fantasy will lead to another problem, I would like to again turn to you in this forum. I owe you.
Yours faithfully and gratitude Andrey!
Many thanks!!! I started doing
As soon as I receive the result, I will write to you at once
This workflow was simple & stupid but it works : )
Step by step, concept to workflow is below,
Keep in mind, if you want to group different type of web users in one database, you only need to let a property become a key to discriminate them.
For Database Permission,
For field inside "Members" database,
Using "Text" for Type
Dynamic Page,
Setting Url to what you want and correct the link in login button code.
For coding,
In login screen page code ("/home"),
*Remark: No need to drag any dataset in login screen.
import wixUsers from 'wix-users'; import wixData from 'wix-data'; import wixLocation from 'wix-location'; //... export function loginButton_click() { //Coding For logout will delete because it will do in next screen... let userId; let userEmail; // prompt the user to log in wixUsers.promptLogin( {"mode": "login"} ) .then( (user) => { userId = user.id; return user.getEmail(); } ) .then( (email) => { // check if there is an item for the user in the collection userEmail = email; return wixData.query("Members") .eq("_id", userId) .find(); } ) .then( (results) => { // if an item for the user is not found if (results.items.length === 0) { // create an item const toInsert = { "_id": userId, "email": userEmail, "identity": "members" }; // add the item to the collection wixData.insert("Members", toInsert).catch((err)=> { console.log(err); }); } // action when user logged in... wixLocation.to(`/Members/Navigation/${wixUsers.currentUser.id}`); } ) .catch( (err) => { console.log(err); } ); }
In navigation screen,
Adding dataset to get the identity of user, who login to your website.
import wixUsers from 'wix-users'; import wixLocation from 'wix-location'; $w.onReady(function () { //getting identity value, when page finish loading... var identity01 = $w("#memberDataset").getCurrentItem().identity; if (identity01 === "members") { $w("#slogan").text = "TextForMembers"; } else if (identity01 === "manager") { $w("#slogan").text = "TextForManger"; } else if (identity01 === "admin") { $w("#slogan").text = "TextForAdmin"; } else if (identity01 === "employee") { $w("#slogan").text = "TextForEmployee"; } }); export function navigationButton_click() { var identity02 = $w("#memberDataset").getCurrentItem().identity; if (identity02 === "members") { wixLocation.to("/pageformembers"); } else if (identity02 === "manager") { wixLocation.to("/pageformanager"); } else if (identity02 === "admin") { wixLocation.to("/pageforadmin"); } else if (identity02 === "employee") { wixLocation.to("/pageforemployee"); } } export function logOutButton_click() { wixUsers.logout(); wixLocation.to("/home"); }
Each navigation page,
Add dataset to go back navigation screen because of my lazy : )
If you don't want to add dataset, you can use code to do so.
import wixLocation from 'wix-location'; //... export function backButton-click() { wixLocation.to(`/Members/Navigation/${wixUsers.currentUser.id}`); }
General remark,
1. Setting page's permission to member only.
2. Member registration approval base on what you like.
3. wixLocation.to("/page");
The ("/page") refer to below,
It will get the purpose you want.
Based on identity, navigating to different pages.
Enjoy. Good luck,
Heson
What will happen if none of the registered will not be assigned a single role?
And I began to torment here is such a process :)
It's just cool !!! You really are a magician
Hi again,
I have created a quick demo for your case, it uses a little trick to do the result you want.
It was very simple.
Let try it.
https://arctiinasestorage0.wixsite.com/mysite
Account for try,
Identity: members
ac: test02@test.com
pw: 1234
Identity: employee
ac: test03@test.com
pw: 1234
Identity: manager
ac: test04@test.com
pw: 1234
Identity: admin
ac: test05@test.com
pw: 1234
Enjoy.
Heson
Option with button "A" is also good
I think about how to insert here:
This
:))
Hello! And if then use different databases. That would click on the button "My profile" link went to the page in view of its role. But at the same time the page used his ID and did not go into the office of another participant. And he would be able to look only to himself.
That is, something like this, but to everyone on their page.
Hi,
I have checked the api reference and test on a blank project.
The result is that
Code of dataset cannot add inside login.Therefore, "identity" cannot use for navigation.
Your concept is right, it only can use "wixUsers.currentUser.role". however, options of roles only have "visitor", "admin" & "member" now.
In the other way to do the same result is that
It was a trick more than a coding.
After login,
Navigate to a dynamic Page < only serves for site members
The concept sims to a profile page
After that A button will show.
Many thanks!!! I will wait...
Hi,
It sims to be a big scale but it also can become simple
Although I don't know the language, I can suggest you an inspire.
Just wait a moment, I may create a quick demo to let your project success.
Even better, the registration process would look like this:
For example: the visitor of a site passes registration and automatically without my permission it is registered, but after this procedure it gets on page here with such text:
"Thank you for registering, please wait while the administrator configures your Personal Account"
After that, in the edit panel of the registered visitors' role, the supervisor assigns a role to everyone by finding their email in the table.
It would be better if this was a text version and not boolean
I mean the role in the table
After that, a time later, the visitor comes through the login page already in the personal cabinet with the account of his role.
Thanks to navigation, I want to create an input not only for clients and employees but also for the administrator and the manager. The administrator will change the schedule to follow the scores, and the supervisor will see the overall robot school. For each of them you need to have a diamonic page. Because there may be several administrators responsible for the work done. Judging by my concept and your code it can be done. Especially you are such a magician :) Thank you very much for helping !!!
Here's what happens on the published site
For example, this is the main page of the site. Which can view any guest.
Among the visitors of the site, there are customers and there are employees.
Each of them has a private office. The client on his page can look at his schedule, the number of lessons he has completed, how many lessons are left for a particular subject, the materials that he needs to be taught. This page helps parents watch how their children learn. And the employee on his page can, look at his schedule, and the forms for submitting a report for the management, that is, how he had classes today. On the basis of the report he gives, the supervisor can look at the general state of affairs in the school and the client how they pass classes. The database is all showing in forms that everyone on the page is different. And with different access.
And so, I need what would already be a registered customer or employee came to their pages
For this they need to enter their personal cabinet. They click on "INPUT" this for example here:
The login screen appears.
Click here
There is this
The customer enters data and presses here
On the site there is this
"Мой профиль" translates as - My profile
Now that the client has reached his page, he needs to click here
In the code this button is called like this
When the client clicks on this button
The collection automatically adds its data to further define its role
And when he pushes here
Then according to the idea he should get on the page intended for clients. The page is dynamic, that would not create a separate page for each client and not edit the code for each one. In addition, on his profile page only his data is displayed and not the data of another client. The program identifies it and displays only its data.
By clicking on this button, the customer must go to his profile
It looks like this
But this does not happen because the code does not have this function
According to your code, I imagined that this would happen after the click of this button
But in principle, after clicking this button, the input to this page does not interfere
The main thing is that after clicking this button
He crossed here
But due to the lack of function for the button
This does not happen
In addition to all of the above, there are also employees with their dynamic page
You said that customers and employees should be in the same collection or database
But when at least employees under their own login even though customers click on this button under their login
The collection automatically registers the entry to the client's dynamic page
So I can not figure out the navigation yet
And I do not understand what you need to connect to this database
Here I am so stupid :)
Strictly speaking about this and I ask for your help. Because of this, I have not even started the code for which I was contacted from the beginning.
Here's what's on my page:
It is necessary that the registered user click here:
And if he's a client, I need him to get on this page
If he is an employee, you need him to visit this page:
This is the code I tried to edit with the navigation.
// За полной документацией по API, включая примеры кода, зайдите на http://wix.to/94BuAAs
$w.onReady(function () {
//TODO: write your page related code here...
});
import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
$w.onReady( () => {
if(wixUsers.currentUser.loggedIn) {
$w("#loginButton").label = "Logout";
$w("#profileButton").show();
} else {
$w("#loginButton").label = "Login";
$w("#profileButton").hide();
}
} );
export function loginButton_click() {
//if loggedIn then loggedOut
//если loggedIn, то loggedOut
if (wixUsers.currentUser.loggedIn) {
wixUsers.logout().then(()=>{
//Update button...
//Кнопка обновления ...
$w("#loginButton").label = "Login";
$w("#profileButton").hide();
});
} else {
let userId;
let userEmail;
// prompt the user to log in
// попросите пользователя войти в систему
wixUsers.promptLogin( {"mode": "login"} ).then( (user) => {
userId = user.id;
return user.getEmail();
} ).then( (email) => {
// check if there is an item for the user in the collection
// проверьте, есть ли элемент для пользователя в коллекции
userEmail = email;
return wixData.query("Members")
.eq("_id", userId)
.find();
} ).then( (results) => {
// if an item for the user is not found
// если элемент для пользователя не найден
if (results.items.length === 0) {
// create an item
// создать элемент
const toInsert = {
"_id": userId,
"email": userEmail,
"identity": false
};
// add the item to the collection
// добавить элемент в коллекцию
wixData.insert("Members", toInsert).catch( (err) => {
console.log(err);
} );
}
// update buttons accordingly
// кнопки обновления соответственно
$w("#loginButton").label = "Logout";
$w("#profileButton").show();
// navigate to page
// перейти на страницу
let identity = $w("#Memberdataset").getCurrentItem().identity;
if (identity === false) {
wixLocation.to(`/Members/${wixUsers.currentUser.id}`);
} else if (identity === true) {
wixLocation.to(`/Members/Employee/${wixUsers.currentUser.id}`);
}
} ).catch( (err) => {
console.log(err);
} );
}
}
I tried to translate it there myself, it's after the sign (//)