Skip to content

Commit

Permalink
Merge pull request #241 from EGA-archive/permissions-ui
Browse files Browse the repository at this point in the history
Permissions UI
  • Loading branch information
costero-e authored Nov 8, 2023
2 parents 900b05f + dfd3034 commit 93b2b56
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 242 deletions.
2 changes: 1 addition & 1 deletion beacon/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
#
# Database connection
#
database_host = 'mongo'
database_host = '127.0.0.1'
database_port = 27017
database_user = 'root'
database_password = 'example'
Expand Down
78 changes: 13 additions & 65 deletions permissions/permissions-ui/bash/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,13 @@
import time
from django.http import HttpResponseRedirect, HttpResponseBadRequest
import logging

import json
import yaml
from pymongo.mongo_client import MongoClient
import imp
from django.urls import resolve

# load a source module from a file
file, pathname, description = imp.find_module('beacon', [''])
my_module = imp.load_module('beacon', file, pathname, description)

from beacon import conf

client = MongoClient(
"mongodb://{}:{}@{}:{}/{}?authSource={}".format(
conf.database_user,
conf.database_password,
conf.database_host,
conf.database_port,
conf.database_name,
conf.database_auth_source,
)
)




LOG = logging.getLogger(__name__)


def add_public_datasets(list_datasets):
with open("../beacon/permissions/public_datasets.yml", 'r') as pfile:
public_datasets = yaml.safe_load(pfile)
Expand All @@ -56,7 +35,6 @@ def add_registered_datasets(list_users, list_datasets):
registered_datasets = yaml.safe_load(pfile)
pfile.close
for user in list_users:
print(user)
registered_datasets[user]=[]
for dataset in list_datasets:
if dataset not in registered_datasets[user]:
Expand All @@ -65,16 +43,6 @@ def add_registered_datasets(list_users, list_datasets):
yaml.dump(registered_datasets, pfile)
pfile.close

def load_datasets():
results = client.beacon.get_collection('datasets').find({}, {"id": 1})
results = list(results)
list_of_datasets=[]
for object in results:
for k,v in object.items():
if k == 'id':
list_of_datasets.append(v)
return list_of_datasets

def load_public_datasets():
with open("../beacon/permissions/public_datasets.yml", 'r') as pfile:
public_datasets = yaml.safe_load(pfile)
Expand Down Expand Up @@ -105,19 +73,12 @@ def load_users():

return list_users

def load_registered_datasets(user):
with open("../beacon/permissions/registered_datasets.yml", 'r') as pfile:
def load_registered_datasets():
with open("../beacon/permissions/public_datasets.yml", 'r') as pfile:
registered_datasets = yaml.safe_load(pfile)
pfile.close()

list_registered_datasets=[]

for k, v in registered_datasets.items():
if k == user:
list_registered_datasets = v

return list_registered_datasets

return registered_datasets


def bash_view(request):
Expand All @@ -138,9 +99,8 @@ def bash_view(request):

def public_view(request):
template = "public.html"
datasets=load_datasets()
bash_out=load_public_datasets()
context={'bash_out': bash_out, 'datasets': datasets}
context={'bash_out': bash_out}
if request.method == 'POST':
answer = request.POST.getlist('list', False)
print(answer)
Expand All @@ -153,9 +113,8 @@ def public_view(request):

def controlled_view(request):
template = "controlled.html"
datasets=load_datasets()
bash_out=load_controlled_datasets()
context={'bash_out': bash_out, 'datasets': datasets}
context={'bash_out': bash_out}
if request.method == 'POST':
answer = request.POST.getlist('list', False)
print(answer)
Expand All @@ -169,25 +128,14 @@ def controlled_view(request):
def registered_view(request):
template = "registered.html"
bash_out=load_users()
datasets=load_datasets()
context={}
if request.method == 'GET':
users = request.GET.getlist('userslist', False)
if users != False:
registered_datasets = load_registered_datasets(users[0])
context={'bash_out': bash_out, 'datasets': datasets, 'users': users, 'registered_datasets': registered_datasets}
else:
context={'bash_out': bash_out, 'datasets': datasets, 'users': users}

return render(request, template, context)


registered_datasets=load_registered_datasets()
context={'bash_out': bash_out, 'registered_datasets': registered_datasets['public_datasets']}
if request.method == 'POST':
user = request.POST.getlist('users', False)
datasets_list = request.POST.getlist('list', False)
add_registered_datasets(user, datasets_list)
answer = request.POST.getlist('list', False)
datasets_list = request.POST.getlist('list_datasets', False)
add_registered_datasets(answer, datasets_list)
context = {
'answer': user, 'datasets_list': datasets_list
'answer': answer, 'datasets_list': datasets_list
}
return redirect("bash:index")
return render(request, template, context)
23 changes: 22 additions & 1 deletion permissions/permissions-ui/media/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const btnAdd = document.querySelector('#btnAdd');
const listbox = document.querySelector('#userslist');
const btnRemove = document.querySelector('#btnRemove');
const listbox = document.querySelector('#list');
const framework = document.querySelector('#framework');

btnAdd.onclick = (e) => {
Expand All @@ -21,3 +22,23 @@ btnAdd.onclick = (e) => {
framework.value = '';
framework.focus();
};

// remove selected option
btnRemove.onclick = (e) => {
e.preventDefault();

// save the selected options
let selected = [];

for (let i = 0; i < listbox.options.length; i++) {
selected[i] = listbox.options[i].selected;
}

// remove all selected option
let index = listbox.options.length;
while (index--) {
if (selected[index]) {
listbox.remove(index);
}
}
};
14 changes: 6 additions & 8 deletions permissions/permissions-ui/media/app2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const btnAdd2 = document.querySelector('#btnAdd2');
const btnRemove = document.querySelector('#btnRemove');
const datasets = document.querySelector('#datasets');
const listbox2 = document.querySelector('#list');
const listbox = document.querySelector('#list');
btnAdd2.onclick = (e) => {
e.preventDefault();

Expand All @@ -18,12 +18,10 @@ btnAdd2.onclick = (e) => {

for (let i = 0; i < selected.length; i++) {
console.log(selected[i])
if (!selected[i] == false){
const option = new Option(selected[i], selected[i]);
option.setAttribute('selected', 'selected');
// add it to the list
listbox2.add(option, undefined);
}
listbox.add(option, undefined);
}
// create a new option

Expand All @@ -38,15 +36,15 @@ btnRemove.onclick = (e) => {
// save the selected options
let selected = [];

for (let i = 0; i < listbox2.options.length; i++) {
selected[i] = listbox2.options[i].selected;
for (let i = 0; i < listbox.options.length; i++) {
selected[i] = listbox.options[i].selected;
}

// remove all selected option
let index = listbox2.options.length;
let index = listbox.options.length;
while (index--) {
if (selected[index]) {
listbox2.remove(index);
listbox.remove(index);
}
}
};
24 changes: 12 additions & 12 deletions permissions/permissions-ui/media/mystyle.css
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,11 @@ table {
justify-content: center;
}

#boxdatasets{
margin-left: 5vw;
#boxdatasets {
margin-left: 7vw;
}


.col-3 {
width: 100% !important;
}
Expand Down Expand Up @@ -485,8 +486,6 @@ table {
padding: 4px;
}



.Btn {
display: flex;
align-items: center;
Expand All @@ -500,14 +499,15 @@ table {
overflow: hidden;
transition-duration: .3s;
box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.199);
background-color: rgb(167, 19, 19);
background-color: #760509;
margin-left: 60px;
margin-bottom: -50px;
}

/* plus sign */
.sign {
width: 100%;
transition-duration: .3s;
transition-duration: 0.3s;
display: flex;
align-items: center;
justify-content: center;
Expand All @@ -529,28 +529,28 @@ table {
color: white;
font-size: 1.2em;
font-weight: 600;
transition-duration: .3s;
transition-duration: 0.3s;
}
/* hover effect on button width */
.Btn:hover {
width: 125px;
border-radius: 40px;
transition-duration: .3s;
transition-duration: 0.3s;
}

.Btn:hover .sign {
width: 30%;
transition-duration: .3s;
transition-duration: 0.3s;
padding-left: 20px;
}
/* hover effect button's text */
.Btn:hover .text {
opacity: 1;
width: 70%;
transition-duration: .3s;
transition-duration: 0.3s;
padding-right: 10px;
}
/* button click effect*/
.Btn:active {
transform: translate(2px ,2px);
}
transform: translate(2px, 2px);
}
Loading

0 comments on commit 93b2b56

Please sign in to comment.