Show / Hide boxes only if Current User is Owner of Page

Hi

I have a members section. In the members section there are multiple pages (including a profile page that is visible to the public).

I have some boxes on the members bar I want visible only to the owner of the page. Could anyone point me in the right direction?

I’ve tied this to date, but it’s hiding all the boxes even you are the owner of the page:

import wixUsers from 'wix-users';

$w.onReady(function () {

if (wixUsers.currentUser.Owner) { 
  $w("#box131").show();
  }
  else{	
  $w("#box131").hide(); 
}
    
});

Many thanks!

Thomas

Hi Thomas!

Could you please share a link to your site and specify in which page you’re facing an issue?
Someone from our WixCode team will inspect it and provide you with a solution.

Doron.

Hi Thomas,

I don’t code, but I kept trying and I created this code that is working for me:

(If their profile is a dynamic page, then you can do it)

$w.onReady(function () {

    $w("#dynamicDataset").onReady( () => {
 const ownerid = $w('#dynamicDataset').getCurrentItem()._id;
 
 if (ownerid === wixUsers.currentUser.id) {
            $w('#editbox').show();
            $w('#editbutton').show();
            $w('#pencil').show();
        } else {
            $w("#editbox").hide();
            $w("#editbutton").hide();
            $w("#pencil").hide();
        }
    });

});

I would appreciate your help with the map that Yisrael gave us… I saw that you did such a beautiful interactive map, but it’s not working for me…

Thanks!

1 Like

Hi Blai

Many thanks for the kind words and for your help. Unfortunately, the code isn’t going to work for me. My members pages are set up using Wix Members Area, not my own dynamicDataset pages. I’ll keep playing about and see if anything works.

I’ve started a new thread (a little clearer) here

R:E the interactive map:

To change the icon I added this to Yisrael’s code (where you add the code to the HTML element):

var iconBase = 'https://www.enteryouriconlocaion...';
	var markers = locations.map(function (location) {
        let marker = new google.maps.Marker({
        position: location.position,
        map: map,
	icon: iconBase
							
});

To change the style of the map I used the google developers page (again, added to the section where you add to the HTML element)

Hope it all goes well!

Thomas

Hi Doron

Many thanks for your reply. I don’t think that my original post was very clear about what I wanted/needed. I’ve started a new thread here .

Hope to hear from you soon!

Many thanks

Thomas

Thanks for your answer thomas, I will check your new post in an hour.

About Google Maps I managed to change the icon just exactly as you did (with the help of Google Developers Articles), but I couldn’t change the map style, I will try later too.

What I wonder is how to do that box next to the map that answers to the clicks on the map. I tried to put an invisible input and change the text of the example for an input value and then use that input as a search bar for a repeater, but I couldn’t do it that way.

Did you use a database with more information or how could you do that? (to put the houses informations next to the map and to change that information depending on what they click).

Thanks! I will tell you something about your post in a few minutes :slight_smile:

Hey Thomas,

okay, I checked your post. My main problem is that I’m working with my own sign up system and my own profile pages, no the members area, so I can’t try to use some code to see how solve that… I’m sorry:(

I managed to make what I was asking you this way, but it’s loading quite slowly, I don’t know if you did the same…

That’s a part of the code paste it on the web, not the HTML:

$w.onReady(function () {
    sendLocations();
    $w("#htmlMap").onMessage( (event) => {
 if(event.data === 'hello') {
            sendLocations();
        }
 else {
 let Title = event.data;
            $w("#dataset1").setFilter(wixData.filter().eq("title", title));
        }
    } );
});

Thanks :slight_smile:

hi everyone:

How can someone, who is now registered on the site and directed to the dynamic page, won’t see himself in the repeater as well?

$w(“#dynamicDataset”).onReady( () => {
const ownerid = $w(‘#dynamicDataset’).getCurrentItem()._id;

if (ownerid === wixUsers.currentUser.id ) {

this is great now how should I continue the code if I want to filter this member from being show on the repeater?

How can someone, who is now registered on the site and directed to the dynamic page, won’t see himself in the repeater as well?

Ok, what situation do we have here?

  1. Registered Member → (in which DATABASE ? (OWN or PrivateMembersData) ?
  2. Dynamic-page ok!

What is a dynamic page?

Isn’t it just an “entry” in your DATABSE, which is connected trough a DATASET with your Collection?

  1. Repeater, hmm ok!

What is a repeater?

Isn’t it just a kind of PROJECTOR, which is also connected trough a DATASET with your DATABASE ?

Your green-line to follow…

  1. Registration
  2. Navigation
  3. DATABASE
  4. Used elements (repeater / dataset / dynamic pages)

REGISTRATION: (user-info → ID / E-Mail and so on…)
So let’s say i am now a new User on your site and do a registration.
What happens when i do register on your site?
-a new entry will be created in the PrivateMembersData with some data about me?
(1) e-mail ?
(2) firstName ?
(3) lastName ?

Which data will be saved exactly in the PMD (PrivateMembersData) ?
And which data can be pulled out again of that PMD ?

https://www.wix.com/velo/reference/wix-users/user

https://www.wix.com/velo/reference/wix-users/currentuser

import wixUsers from 'wix-users';
2
3// ...
4
5let user = wixUsers.currentUser;
6
7let userId = user.id;           // "r5cme-6fem-485j-djre-4844c49"
8let isLoggedIn = user.loggedIn; // true
9
10user.getEmail()
11  .then( (email) => {
12    let userEmail = email;      // "user@something.com"
13  } );
14
15user.getRoles()
16  .then( (roles) => {
17    let firstRole = roles[0];
18    let roleName = firstRole.name;                // "Role Name"
19    let roleDescription = firstRole.description;  // "Role Description"
20  } );
21
22user.getPricingPlans()
23  .then( (pricingPlans) => {
24    let firstPlan = pricingPlans[0];
25    let planName = firstPlan.name;          // "Gold"
26    let startDate = firstPlan.startDate;    // Wed Aug 29 2018 09:39:41 GMT-0500 (Eastern Standard Time)
27    let expiryDate = firstPlan.expiryDate;  // Thu Nov 29 2018 08:39:41 GMT-0400 (Eastern Daylight Time)
28  } );

Can i even get more data out of PMD ?
https://www.wix.com/velo/reference/wix-users-backend

import wixUsersBackend from 'wix-users-backend';
2
3export function getUser(id) {
4  return wixUsersBackend.getUser(id)
5    .then((user) => {
6      return user;
7    });
8}
9
10/* Returns a promise that resolves to:
11 *
12 * {
13 *   "id": "dn8sf9c2-4e9f-a02d-a58d-f244d999729a",
14 *   "memberName": "John Doe",
15 *   "firstName": "John",
16 *   "lastName": "Doe",
17 *   "nickname": "johnd",
18 *   "slug": "johnd123",
19 *   "language": "en",
20 *   "status": "ACTIVE",
21 *   "loginEmail": "john.doe@somedomain.com",
22 *   "creationDate": "2019-08-05T11:29:39Z",
23 *   "lastUpdateDate": "2019-08-12T12:29:43.810Z",
24 *   "lastLoginDate": "2019-08-12T13:42:30Z",
25 *   "emails": [
26 *     "john.doe@somedomain.com",
27 *     "doughyjohn@anotherdomain.com"
28 *   ],
29 *   "phones": [
30 *     "5555555555",
31 *     "5555555556"
32 *   ],
33 *   "labels": [
34 *     "contacts-new",
35 *     "contacts-site_members_approved"
36 *   ],
37 *   "picture": {
38 *     "url": "https://.../photo.jpg"
39 *   }
40 *   "customText": "Custom Text",
41 *   "customNumber": 12345
42 * }
43 */

This is just the beginning, of what you have to know, when you want to achive your aim.

Navigation: (user-info → ID / E-Mail and so on…)

Navigate to a local link

CODE EXAMPLE
1import wixLocation from 'wix-location';
2
3// ...
4
5wixLocation.to("/about-me");

I saw a few of your questions. I know it is very confusing to see all that stuff for the first time, but if you want to get your desired projects come true, you should first learn about some coding, taking a carefully look onto the given APIs in the VELO-API-DOCUMENTATION.

Ok, forget about it. I do not want to confuse you even more.

So, how to make it more simple?

  1. I am now a member of your site and my personal-data (like: e-mail/user & owner-id) is saved in your “PrivateMembersData” .

  2. Now you want me to navigate to a special page (dynamic-page) where you will show me some stuff of one of your DATABASES, but you do not want to let me see my own DATA (which already have been created on one of your sites [because i am so fast xD]). Nowsome of my generated DATA is in one of your DBs, and now i am on one of the pages, where all the data is shown (mine included).

  3. But you do not want that i see my own generated data in this (element → table/repeater). What you have to do now?

  4. Figuring out my — ID (using the wix-user-API).

  5. Searching the DB for my ID with the related DATA.

  6. Do an IF-ELSE-STATEMENT to check if or not!

  7. If YES —> then … do some code… (hide my own content, because it’s me!)

  8. If NO —> do some other code… (show my own content, because it’s not me!)

and so on …

This is how i would solve it —> follow your logical way… step-by-step.:roll_eyes::wink: