Skip to content

Commit

Permalink
Client-format
Browse files Browse the repository at this point in the history
  • Loading branch information
dannon committed May 11, 2018
1 parent 2a21e27 commit a277a40
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 103 deletions.
36 changes: 21 additions & 15 deletions client/galaxy/scripts/apps/analysis.js
Expand Up @@ -134,11 +134,13 @@ window.app = function app(options, bootstrapped) {
var sharingInstance = Vue.extend(Sharing);
var vm = document.createElement("div");
this.page.display(vm);
new sharingInstance({ propsData: {
id: QueryStringParsing.get("id"),
plural_name: "Visualizations",
model_class: "Visualization",
} }).$mount(vm);
new sharingInstance({
propsData: {
id: QueryStringParsing.get("id"),
plural_name: "Visualizations",
model_class: "Visualization"
}
}).$mount(vm);
},

show_workflows_published: function() {
Expand Down Expand Up @@ -188,11 +190,13 @@ window.app = function app(options, bootstrapped) {
var sharingInstance = Vue.extend(Sharing);
var vm = document.createElement("div");
this.page.display(vm);
new sharingInstance({ propsData: {
id: QueryStringParsing.get("id"),
plural_name: "Histories",
model_class: "History",
} }).$mount(vm);
new sharingInstance({
propsData: {
id: QueryStringParsing.get("id"),
plural_name: "Histories",
model_class: "History"
}
}).$mount(vm);
},

show_histories_import: function() {
Expand Down Expand Up @@ -265,11 +269,13 @@ window.app = function app(options, bootstrapped) {
var sharingInstance = Vue.extend(Sharing);
var vm = document.createElement("div");
this.page.display(vm);
new sharingInstance({ propsData: {
id: QueryStringParsing.get("id"),
plural_name: "Pages",
model_class: "Page",
} }).$mount(vm);
new sharingInstance({
propsData: {
id: QueryStringParsing.get("id"),
plural_name: "Pages",
model_class: "Page"
}
}).$mount(vm);
},

show_plugins: function() {
Expand Down
2 changes: 1 addition & 1 deletion client/galaxy/scripts/components/RuleCollectionBuilder.vue
Expand Up @@ -784,7 +784,7 @@ const RuleModalHeader = {
const RuleModalMiddle = {
template: `<div class="middle flex-row flex-row-container"><slot></slot></div>`
}
};
const RuleModalFooter = {
template: `
Expand Down
60 changes: 38 additions & 22 deletions client/galaxy/scripts/components/Sharing.vue
Expand Up @@ -117,7 +117,9 @@ export default {
return this.item.published ? "accessible via link and published" : "accessible via link";
},
item_url() {
return `${window.location.protocol}//${window.location.hostname}:${window.location.port}${Galaxy.root}${this.item.username_and_slug}`;
return `${window.location.protocol}//${window.location.hostname}:${window.location.port}${Galaxy.root}${
this.item.username_and_slug
}`;
},
item_url_parts() {
let str = this.item_url;
Expand All @@ -141,12 +143,12 @@ export default {
new_username: "",
err_msg: null,
pencil_url: `${Galaxy.root}static/images/fugue/pencil.png`,
item : {
item: {
title: "title",
username_and_slug: "username_and_slug",
importable: false,
published: false,
users_shared_with: [],
users_shared_with: []
}
};
},
Expand All @@ -165,19 +167,19 @@ export default {
this.item = response.data;
this.ready = true;
})
.catch(error => this.err_msg = error.response.data.err_msg)
.catch(error => (this.err_msg = error.response.data.err_msg));
},
setUsername: function() {
axios
.put(`${Galaxy.root}api/users/${Galaxy.user.id}/information/inputs`, {
username: this.new_username || ''
username: this.new_username || ""
})
.then(response => {
this.err_msg = null;
this.has_username = true;
this.getModel();
})
.catch(error => this.err_msg = error.response.data.err_msg);
.catch(error => (this.err_msg = error.response.data.err_msg));
},
setSharing: function(action, user_id) {
axios
Expand All @@ -188,33 +190,47 @@ export default {
.then(response => {
Object.assign(this.item, response.data);
})
.catch(error => this.err_msg = error.response.data.err_msg);
.catch(error => (this.err_msg = error.response.data.err_msg));
},
createSlugHandler: function() {
var on_start = function( text_elt ) {
var on_start = function(text_elt) {
// Replace URL with URL text.
$('#item-url').hide();
$('#item-url-text').show();
$("#item-url").hide();
$("#item-url-text").show();
// Allow only lowercase alphanumeric and '-' characters in slug.
text_elt.keyup(function(){
text_elt.val( $(this).val().replace(/\s+/g,'-').replace(/[^a-zA-Z0-9\-]/g,'').toLowerCase() )
text_elt.keyup(function() {
text_elt.val(
$(this)
.val()
.replace(/\s+/g, "-")
.replace(/[^a-zA-Z0-9\-]/g, "")
.toLowerCase()
);
});
};
var on_finish = function( text_elt ) {
var on_finish = function(text_elt) {
// Replace URL text with URL.
$('#item-url-text').hide();
$('#item-url').show();
$("#item-url-text").hide();
$("#item-url").show();
// Set URL to new value.
var new_url = $('#item-url-text').text();
var item_url_obj = $('#item-url');
item_url_obj.attr( "href", new_url );
item_url_obj.text( new_url );
var new_url = $("#item-url-text").text();
var item_url_obj = $("#item-url");
item_url_obj.attr("href", new_url);
item_url_obj.text(new_url);
};
async_save_text("edit-identifier", "item-identifier",
this.slug_url, "new_slug", null, false, 0,
on_start, on_finish);
async_save_text(
"edit-identifier",
"item-identifier",
this.slug_url,
"new_slug",
null,
false,
0,
on_start,
on_finish
);
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion client/galaxy/scripts/mvc/ui/ui-modal.js
Expand Up @@ -10,7 +10,7 @@ export var View = Backbone.View.extend({
backdrop: true,
height: null,
width: null,
xlarge: false, /* BS4 max-width already expanded in Galaxy, expand even more if true. */
xlarge: false /* BS4 max-width already expanded in Galaxy, expand even more if true. */,
closing_events: false,
closing_callback: null,
title_separator: true
Expand Down
130 changes: 66 additions & 64 deletions client/galaxy/scripts/utils/async-save-text.js
Expand Up @@ -26,75 +26,77 @@ function async_save_text(
}

// Set up input element.
$(`#${click_to_edit_elt}`).off().click(() => {
// Check if this is already active
if ($("#renaming-active").length > 0) {
return;
}
var text_elt = $(`#${text_elt_id}`);
var old_text = text_elt.text();
var t;

if (use_textarea) {
t = $("<textarea></textarea>")
.attr({ rows: num_rows, cols: num_cols })
.text($.trim(old_text));
} else {
t = $("<input type='text'></input>").attr({
value: $.trim(old_text),
size: num_cols
});
}
t.attr("id", "renaming-active");
t.blur(function() {
$(this).remove();
text_elt.show();
if (on_finish) {
on_finish(t);
$(`#${click_to_edit_elt}`)
.off()
.click(() => {
// Check if this is already active
if ($("#renaming-active").length > 0) {
return;
}
});
t.keyup(function(e) {
if (e.keyCode === 27) {
// Escape key
$(this).trigger("blur");
} else if (e.keyCode === 13) {
// Enter key submits
var ajax_data = {};
ajax_data[text_parm_name] = $(this).val();
$(this).trigger("blur");
$.ajax({
url: save_url,
data: ajax_data,
error: function() {
alert(`Text editing for elt ${text_elt_id} failed`);
// TODO: call finish or no? For now, let's not because error occurred.
},
success: function(processed_text) {
// Set new text and call finish method.
if (processed_text !== "") {
text_elt.text(processed_text);
} else {
text_elt.html("<em>None</em>");
}
if (on_finish) {
on_finish(t);
}
}
var text_elt = $(`#${text_elt_id}`);
var old_text = text_elt.text();
var t;

if (use_textarea) {
t = $("<textarea></textarea>")
.attr({ rows: num_rows, cols: num_cols })
.text($.trim(old_text));
} else {
t = $("<input type='text'></input>").attr({
value: $.trim(old_text),
size: num_cols
});
}
});
t.attr("id", "renaming-active");
t.blur(function() {
$(this).remove();
text_elt.show();
if (on_finish) {
on_finish(t);
}
});
t.keyup(function(e) {
if (e.keyCode === 27) {
// Escape key
$(this).trigger("blur");
} else if (e.keyCode === 13) {
// Enter key submits
var ajax_data = {};
ajax_data[text_parm_name] = $(this).val();
$(this).trigger("blur");
$.ajax({
url: save_url,
data: ajax_data,
error: function() {
alert(`Text editing for elt ${text_elt_id} failed`);
// TODO: call finish or no? For now, let's not because error occurred.
},
success: function(processed_text) {
// Set new text and call finish method.
if (processed_text !== "") {
text_elt.text(processed_text);
} else {
text_elt.html("<em>None</em>");
}
if (on_finish) {
on_finish(t);
}
}
});
}
});

if (on_start) {
on_start(t);
}
// Replace text with input object and focus & select.
text_elt.hide();
t.insertAfter(text_elt);
t.focus();
t.select();
if (on_start) {
on_start(t);
}
// Replace text with input object and focus & select.
text_elt.hide();
t.insertAfter(text_elt);
t.focus();
t.select();

return;
});
return;
});
}

// ============================================================================
Expand Down

0 comments on commit a277a40

Please sign in to comment.