Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly use and display user's name and projects #435

Merged
merged 12 commits into from
Mar 14, 2017
19 changes: 0 additions & 19 deletions knora-ontologies/knora-admin.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -320,20 +320,6 @@



### http://www.knora.org/ontology/knora-base#projectBasepath

:projectBasepath rdf:type owl:DatatypeProperty ;

rdfs:subPropertyOf :objectCannotBeMarkedAsDeleted ;

rdfs:comment "Basepath for digital objects which belong to this project"@en ;

:subjectClassConstraint :knoraProject ;

:objectDatatypeConstraint xsd:string .



### http://www.knora.org/ontology/knora-base#projectDataGraph

:projectDataGraph rdf:type owl:DatatypeProperty ;
Expand Down Expand Up @@ -596,10 +582,6 @@
owl:onProperty :projectDataGraph ;
owl:cardinality "1"^^xsd:nonNegativeInteger
] ,
[ rdf:type owl:Restriction ;
owl:onProperty :projectBasepath ;
owl:cardinality "1"^^xsd:nonNegativeInteger
] ,
[ rdf:type owl:Restriction ;
owl:onProperty :status ;
owl:cardinality "1"^^xsd:nonNegativeInteger
Expand Down Expand Up @@ -674,7 +656,6 @@
:projectDescription "Knora System Project" ;
:projectOntologyGraph "http://www.knora.org/ontology/knora-base" ;
:projectDataGraph "-" ;
:projectBasepath "-"^^xsd:string ;
:status "true"^^xsd:boolean ;
:hasSelfJoinEnabled "false"^^xsd:boolean .

Expand Down
109 changes: 70 additions & 39 deletions salsah/src/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,31 @@
* language selection
*/
SALSAH.reset_project_selection = function() {

$('#projectctrl').text(s_('_project') + ' : ');
if (SALSAH.userdata === null) {
if (SALSAH.userprofile === null) {
$('#projectctrl').text('-');
}
else if (SALSAH.userdata.projects_info === undefined) {
else if (SALSAH.userprofile.projects_info === undefined) {
$('#projectctrl').text('-');
}
else {
if (SALSAH.userdata.projects_info.length > 1) {


if (Object.keys(SALSAH.userprofile.projects_info).length > 1) {

if (SALSAH.userprofile.active_project === undefined) {
for (id in SALSAH.userprofile.projects_info) {
SALSAH.userprofile.active_project = id;
break;
}
}
// set the user's active project
SALSAH.userdata.active_project = SALSAH.userdata.projects[0];

var psel = $('<select>').appendTo('#projectctrl').on('change', function(event){
SALSAH.userdata.active_project = $(this).val();
var psel = $('<select id="project_sel">').appendTo('#projectctrl').on('change', function(event){
SALSAH.userprofile.active_project = $(this).val();
window.sessionStorage.setItem('userprofile', JSON.stringify(SALSAH.userprofile));

// TODO: https://github.com/dhlab-basel/Knora/issues/147
/*SALSAH.ApiPost('userdata', {project: $(this).val()}, function(data) {
if (data.status == ApiErrors.OK) {
Expand All @@ -104,19 +115,24 @@
});*/
});

for(var i in SALSAH.userdata.projects_info) {
if (SALSAH.userdata.projects_info[i].id == SALSAH.userdata.active_project) {
psel.append($('<option>').attr({selected: true}).val(SALSAH.userdata.projects_info[i].id).text(SALSAH.userdata.projects_info[i].shortname));
for (var i in SALSAH.userprofile.projects_info) {
if (i == SALSAH.userprofile.active_project) {
psel.append($('<option>').attr({selected: true}).val(i).text(SALSAH.userprofile.projects_info[i].shortname));
}
else {
psel.append($('<option>').val(SALSAH.userdata.projects_info[i].id).text(SALSAH.userdata.projects_info[i].shortname));
psel.append($('<option>').val(i).text(SALSAH.userprofile.projects_info[i].shortname));
}
}
}
else if (SALSAH.userdata.projects_info.length == 1) {
$('#projectctrl').append(SALSAH.userdata.projects_info[0].shortname);
// set the user's active project
SALSAH.userdata.active_project = SALSAH.userdata.projects[0];
else if (Object.keys(SALSAH.userprofile.projects_info).length == 1) {
if (SALSAH.userprofile.active_project === undefined) {
for (id in SALSAH.userprofile.projects_info) {
SALSAH.userprofile.active_project = id;
break;
}
}

$('#projectctrl').append(SALSAH.userprofile.projects_info[SALSAH.userprofile.active_project].shortname);
}
else {
$('#projectctrl').append('-');
Expand All @@ -129,13 +145,13 @@
var lc = $('#langctrl');

var build_lang_ctrl = function() {
if (SALSAH.userdata.lang === undefined) SALSAH.userdata.lang = 'de';
if (SALSAH.userprofile.userData.lang === undefined) SALSAH.userprofile.userData.lang = 'de';
for (var l in langs) {
if (l == SALSAH.userdata.lang) {
if (l == SALSAH.userprofile.userData.lang) {
lc.append(' ' + l);
}
else {
lc.append(' ').append($('<a>').attr({href: '#'}).data({lang: l, language_id: SALSAH.userdata.lang[l]}).on('click', function(data) {
lc.append(' ').append($('<a>').attr({href: '#'}).data({lang: l, language_id: l}).on('click', function(data) {
if (confirm(s_('_langchangeq'))) {
var newref = 'http://' + window.location.host + window.location.pathname + '?lang=' + $(this).data('lang');
location.replace(newref);
Expand Down Expand Up @@ -174,13 +190,15 @@
//$('#dologout').simpledialog('logoutbox', {'class': 'loginbox', width: 400, positioning: 'upper'});
$('#userctrl').append($('<img>').attr({id: 'dologin', src: 'app/icons/24x24/user.png', title: s_('_login')})
.simpledialog('loginbox', {'class': 'loginbox', width: 400, positioning: 'upper', focus: '#user_id'}));
var json_userdata;
if ((json_userdata = window.sessionStorage.getItem('userdata')) != null) {
SALSAH.userdata = JSON.parse(json_userdata);

var json_userprofile;
if ((json_userprofile = window.sessionStorage.getItem('userprofile')) != null) {
SALSAH.userprofile = JSON.parse(json_userprofile);
}

SALSAH.reset_project_selection();

$('#login_button').on('click', function(){
$('#login_button').on('click', function() {
var credentials = {
salsah_username: $('#user_id').val(),
salsah_password: $('#password').val()
Expand All @@ -192,7 +210,8 @@
// Now do a request to Sipi providing the Knora session id.
// When retrieving a file from Sipi (e.g. an IIIF URL), Sipi can send the session id to Knora with the request,
// identifying the user that is making the request to Knora.
window.sessionStorage.setItem('userdata', JSON.stringify(SALSAH.userdata));
SALSAH.userprofile = data.userProfile;
window.sessionStorage.setItem('userprofile', JSON.stringify(SALSAH.userprofile));

$.ajax({
url: SIPI_URL + SIPI_LOGIN_ROUTE,
Expand All @@ -214,23 +233,28 @@

$('#dologin').simpledialog('loginbox', 'close');

$('#userctrl').empty().append(s_('_user') + ' : ' + SALSAH.userdata.username)
$('#userctrl').empty().append(s_('_user') + ' : ' + SALSAH.userprofile.userData.firstname + ' ' + SALSAH.userprofile.userData.lastname)
.append($('<img>').attr({id: 'dologout', src: 'app/icons/24x24/delete_user.png', title: s_('_logout')})
.simpledialog('logoutbox', {'class': 'loginbox', width: 400, positioning: 'upper'})
);
if (SALSAH.reset_project_selection !== undefined) SALSAH.reset_project_selection();

if (SALSAH.userprofile.projects_info) {
if (SALSAH.userprofile.active_project === undefined) {
for (id in SALSAH.userprofile.projects_info) {
SALSAH.userprofile.active_project = id;
break;
}
}

if (SALSAH.userdata.projects_info) {
var active_project = SALSAH.userdata.active_project;
var selele;
$('#searchlimsel')
.empty()
.append(s_('_limitsearch'))
.append(selele = $('<select>').attr({id: 'limitproject', title: 'limit search to project'}));
selele.append($('<option>').attr({title: 'ALl'}).val(-1).text('-'));
for (var p in SALSAH.userdata.projects_info) {
selele.append($('<option>').attr({title: SALSAH.userdata.projects_info[p].longname}).val(SALSAH.userdata.projects_info[p].id).text(SALSAH.userdata.projects_info[p].shortname));
for (var p in SALSAH.userprofile.projects_info) {
selele.append($('<option>').attr({title: SALSAH.userprofile.projects_info[p].longname}).val(SALSAH.userprofile.projects_info[p].id).text(SALSAH.userprofile.projects_info[p].shortname));
}
}

Expand All @@ -245,8 +269,8 @@
$('#logout_button').on('click', function() {
SALSAH.ApiDelete('session', function(data) {
if (data.status == ApiErrors.OK) {
window.sessionStorage.removeItem('userdata');
SALSAH.userdata = null;
window.sessionStorage.removeItem('userprofile');
SALSAH.userprofile = null;
// invalidate cookie obtained from Sipi when logging in to Knora
$.ajax({
url: SIPI_URL + SIPI_LOGOUT_ROUTE,
Expand Down Expand Up @@ -279,8 +303,8 @@
});
});

if (SALSAH.userdata.user_id !== undefined) {
$('#userctrl').empty().append(s_('_user') + ' : ' + SALSAH.userdata.username)
if (SALSAH.userprofile.userData.email !== undefined) {
$('#userctrl').empty().append(s_('_user') + ' : ' + SALSAH.userprofile.userData.firstname + ' ' + SALSAH.userprofile.userData.lastname)
.append($('<img>').attr({id: 'dologout', src: 'app/icons/24x24/delete_user.png', title: s_('_logout')})
.simpledialog('logoutbox', {'class': 'loginbox', width: 400, positioning: 'upper'})
);
Expand Down Expand Up @@ -333,33 +357,40 @@
);


if (SALSAH.userdata.projects_info) {
var active_project = SALSAH.userdata.active_project;
if (SALSAH.userprofile.projects_info) {
var selele;
$('#searchlimsel')
.empty()
.append(s_('_limitsearch'))
.append(selele = $('<select>').attr({id: 'limitproject', title: 'limit search to project'}));
selele.append($('<option>').attr({title: 'ALl'}).val(-1).text('-'));
for (var p in SALSAH.userdata.projects_info) {
selele.append($('<option>').attr({title: SALSAH.userdata.projects_info[p].longname}).val(SALSAH.userdata.projects_info[p].id).text(SALSAH.userdata.projects_info[p].shortname));
for (var p in SALSAH.userprofile.projects_info) {
if (p == SALSAH.userprofile.active_project) {
selele.append($('<option>').attr({title: SALSAH.userprofile.projects_info[p].longname, selected: true}).val(p).text(SALSAH.userprofile.projects_info[p].shortname));
}
else {
selele.append($('<option>').attr({title: SALSAH.userprofile.projects_info[p].longname}).val(p).text(SALSAH.userprofile.projects_info[p].shortname));
}
}
}

};

$(function(){
if (urlparams["lang"] !== undefined) {
SALSAH.userdata = {lang: urlparams["lang"]};
if (SALSAH.userprofile === undefined) SALSAH.userprofile = {};
if (SALSAH.userprofile.userData === undefined) SALSAH.userprofile.userData = {};
if (urlparams["lang"] !== undefined) {
SALSAH.userprofile.userData.lang = urlparams["lang"];
}
else {
SALSAH.userdata = {lang: 'en'};
SALSAH.userprofile.userData.lang = 'en';
}
$.get('lang/' + SALSAH.userdata.lang + '.json', function(data) {
$.get('lang/' + SALSAH.userprofile.userData.lang + '.json', function(data) {
strings = data;
init_gui();
}, 'json');
});

</script>
<link id="loadcss" rel="stylesheet" type="text/css" href="default.css" />
<link href="vendor/bootstrap/css/bootstrap-btn-only.css" rel="stylesheet">
Expand Down
2 changes: 1 addition & 1 deletion salsah/src/public/js/00_init_javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ var s_ = function(key) {

SALSAH.reload_css = function() {
var href = $('#loadcss').attr('href'); + ',#';
if ((SALSAH.userdata !== null) && (SALSAH.userdata.active_project !== undefined)) href += '&project_id=' + SALSAH.userdata.active_project;
if ((SALSAH.userprofile.active_project !== undefined)) href += '&project_id=' + SALSAH.userprofile.active_project;

$('#loadcss').attr({href: href});
}
Expand Down
33 changes: 0 additions & 33 deletions salsah/src/public/js/01_salsah_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ SALSAH.ApiGet = function() {
}

send_params.success = function(data, textStatus, jqXHR) {
if ((typeof data == 'object') && (typeof data.userdata == 'object')) {
SALSAH.userdata = data.userdata;
delete data.userdata;
}
if (typeof success_cb == 'function') {
success_cb(data, textStatus, jqXHR);
}
Expand Down Expand Up @@ -182,25 +178,13 @@ SALSAH.ApiPost = function() {
}
}
}
/*
if (SALSAH.userdata !== undefined) {
if (send_params.data === undefined) {
send_params.data = {};
}
send_params.data.userdata = SALSAH.userdata;
}
*/

//
// convert all data to JSON before sending...
//
send_params.data = JSON.stringify(send_params.data);

send_params.success = function(data, textStatus, jqXHR) {
if ((typeof data == 'object') && (typeof data.userdata == 'object')) {
SALSAH.userdata = data.userdata;
delete data.userdata;
}
if (typeof success_cb == 'function') {
success_cb(data, textStatus, jqXHR);
}
Expand Down Expand Up @@ -272,25 +256,12 @@ SALSAH.ApiPut = function() {
}
}

/*
if (SALSAH.userdata !== undefined) {
if (send_params.data === undefined) {
send_params.data = {};
}
send_params.data.userdata = SALSAH.userdata;
}
*/

//
// convert all data to JSON before sending...
//
send_params.data = JSON.stringify(send_params.data);

send_params.success = function(data, textStatus, jqXHR) {
if ((typeof data == 'object') && (typeof data.userdata == 'object')) {
SALSAH.userdata = data.userdata;
delete data.userdata;
}
if (typeof success_cb == 'function') {
success_cb(data, textStatus, jqXHR);
}
Expand Down Expand Up @@ -351,10 +322,6 @@ SALSAH.ApiDelete = function() {
send_params.data = JSON.stringify(send_params.data);

send_params.success = function(data, textStatus, jqXHR) {
if ((typeof data == 'object') && (typeof data.userdata == 'object')) {
SALSAH.userdata = data.userdata;
delete data.userdata;
}
if (typeof success_cb == 'function') {
success_cb(data, textStatus, jqXHR);
}
Expand Down
2 changes: 1 addition & 1 deletion salsah/src/public/js/imagebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,7 @@ $(function() {
SALSAH.ApiPost('resources', { // use resources route because it is a knora-base_linkObject resource that is to be created
restype_id: "http://www.knora.org/ontology/knora-base#LinkObj",
label: window_content.find(".__label").val(),
project_id: SALSAH.userdata.projects[0],
project_id: SALSAH.active_project,
properties: {
"http://www.knora.org/ontology/knora-base#hasLinkTo": resIdsArr,
"http://www.knora.org/ontology/knora-base#hasComment": [{richtext_value: rt_props}]
Expand Down
2 changes: 1 addition & 1 deletion salsah/src/public/js/jquery.geonameobj.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
$this.data('localdata', localdata);
my.defaultData = {
userName: 'milchkannen',
lang: SALSAH.userdata.lang
lang: SALSAH.userprofile.userData.lang
};

$this.html(
Expand Down
2 changes: 1 addition & 1 deletion salsah/src/public/js/jquery.geonames.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@
response($.map(data.geonames, function (item) {
var displayName = undefined;
for (var i in item.alternateNames) { // here we search through the alternate names to get the proper language
if (item.alternateNames[i].lang == SALSAH.userdata.lang) {
if (item.alternateNames[i].lang == SALSAH.userprofile.userData.lang) {
if (displayName === undefined) {
displayName = item.alternateNames[i].name;
}
Expand Down
2 changes: 1 addition & 1 deletion salsah/src/public/js/jquery.resadd.js
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@
SALSAH.ApiPost('resources', {
restype_id: rtinfo.name,
properties: propvals,
project_id: SALSAH.userdata.projects[0], // TODO: take the user's active project here: https://github.com/dhlab-basel/Knora/issues/118
project_id: SALSAH.userprofile.active_project,
file: file,
label: labelStr

Expand Down
4 changes: 0 additions & 4 deletions salsah/src/public/js/jquery.valcomment.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
localdata.settings.comment = localdata.ele.find('textarea').val();
SALSAH.ApiPut('values/' + encodeURIComponent(localdata.settings.value_id),
{
project_id: SALSAH.userdata.projects[0], // TODO: how to get this information in a correct way? https://github.com/dhlab-basel/Knora/issues/118
comment: localdata.settings.comment
},
function(data) {
Expand Down Expand Up @@ -131,9 +130,6 @@
.append($('<span>').addClass('glyphicon glyphicon-trash'))
.on('click', function (event) {
SALSAH.ApiDelete('valuecomments/' + encodeURIComponent(localdata.settings.value_id),
{
project_id: SALSAH.userdata.projects[0], // TODO: how to get this information in a correct way? https://github.com/dhlab-basel/Knora/issues/118
},
function(data) {
if (data.status == ApiErrors.OK) {
localdata.ele.empty().css({'display': 'none'});
Expand Down
Loading