Modified tags in metadata dialog and moved column right to name

This commit is contained in:
xseris 2017-12-07 00:59:36 +01:00
parent f21230804b
commit b16941777e
8 changed files with 320 additions and 142 deletions

View File

@ -139,6 +139,7 @@ public abstract class ProjectManager {
_projectsMetadata.put(project.id, projectMetadata); _projectsMetadata.put(project.id, projectMetadata);
if (_projectsTags == null) { if (_projectsTags == null) {
_projectsTags = new HashMap<String, Integer>(); _projectsTags = new HashMap<String, Integer>();
<<<<<<< Upstream, based on origin/master
} }
String[] tags = projectMetadata.getTags(); String[] tags = projectMetadata.getTags();
if (tags != null) { if (tags != null) {
@ -148,6 +149,16 @@ public abstract class ProjectManager {
} else { } else {
_projectsTags.put(tag, 1); _projectsTags.put(tag, 1);
} }
=======
String[] tags = projectMetadata.getTags();
if (tags != null) {
for (String tag : tags) {
if (_projectsTags.containsKey(tag)) {
_projectsTags.put(tag, _projectsTags.get(tag) + 1);
} else {
_projectsTags.put(tag, 1);
}
>>>>>>> 529b6bd Modified tags in metadata dialog and moved column right to name
} }
} }
} }

View File

@ -57,6 +57,7 @@ import com.google.refine.util.JSONUtilities;
import com.google.refine.util.ParsingUtilities; import com.google.refine.util.ParsingUtilities;
public class ProjectMetadata implements Jsonizable { public class ProjectMetadata implements Jsonizable {
private final Date _created; private final Date _created;
private Date _modified; private Date _modified;
private Date written = null; private Date written = null;
@ -106,29 +107,37 @@ public class ProjectMetadata implements Jsonizable {
throws JSONException { throws JSONException {
writer.object(); writer.object();
writer.key("name"); writer.value(_name); writer.key("name");
writer.key("created"); writer.value(ParsingUtilities.dateToString(_created)); writer.value(_name);
writer.key("modified"); writer.value(ParsingUtilities.dateToString(_modified));
writer.key("creator"); writer.value(_creator);
writer.key("contributors"); writer.value(_contributors);
writer.key("subject"); writer.value(_subject);
writer.key("description"); writer.value(_description);
writer.key("rowCount"); writer.value(_rowCount);
writer.key("customMetadata"); writer.object();
for (String key : _customMetadata.keySet()) {
Serializable value = _customMetadata.get(key);
writer.key(key);
writer.value(value);
}
writer.endObject();
writer.key("tags"); writer.key("tags");
writer.array(); writer.array();
for (String tag : _tags) { for (String tag : _tags) {
writer.value(tag); writer.value(tag);
} }
writer.endArray(); writer.endArray();
writer.key("created");
writer.value(ParsingUtilities.dateToString(_created));
writer.key("modified");
writer.value(ParsingUtilities.dateToString(_modified));
writer.key("creator");
writer.value(_creator);
writer.key("contributors");
writer.value(_contributors);
writer.key("subject");
writer.value(_subject);
writer.key("description");
writer.value(_description);
writer.key("rowCount");
writer.value(_rowCount);
writer.key("customMetadata");
writer.object();
for (String key : _customMetadata.keySet()) {
Serializable value = _customMetadata.get(key);
writer.key(key);
writer.value(value);
}
writer.endObject();
// write JSONArray directly // write JSONArray directly
if (_importOptionMetadata.length() > 0) { if (_importOptionMetadata.length() > 0) {
@ -143,12 +152,16 @@ public class ProjectMetadata implements Jsonizable {
} }
if (isSaveMode(options)) { if (isSaveMode(options)) {
writer.key("password"); writer.value(_password); writer.key("password");
writer.value(_password);
writer.key("encoding"); writer.value(_encoding); writer.key("encoding");
writer.key("encodingConfidence"); writer.value(_encodingConfidence); writer.value(_encoding);
writer.key("encodingConfidence");
writer.value(_encodingConfidence);
writer.key("preferences"); _preferenceStore.write(writer, options); writer.key("preferences");
_preferenceStore.write(writer, options);
} }
writer.endObject(); writer.endObject();
@ -160,8 +173,7 @@ public class ProjectMetadata implements Jsonizable {
public void writeWithoutOption(JSONWriter writer) public void writeWithoutOption(JSONWriter writer)
throws JSONException { throws JSONException {
write(writer, write(writer, new Properties());
new Properties());
} }
private boolean isSaveMode(Properties options) { private boolean isSaveMode(Properties options) {
@ -172,16 +184,20 @@ public class ProjectMetadata implements Jsonizable {
return written == null || _modified.after(written); return written == null || _modified.after(written);
} }
public void write(JSONWriter jsonWriter) throws JSONException { public void write(JSONWriter jsonWriter)
throws JSONException {
write(jsonWriter, false); write(jsonWriter, false);
} }
/** /**
* @param jsonWriter writer to save metadatea to * @param jsonWriter
* @param onlyIfDirty true to not write unchanged metadata * writer to save metadatea to
* @param onlyIfDirty
* true to not write unchanged metadata
* @throws JSONException * @throws JSONException
*/ */
public void write(JSONWriter jsonWriter, boolean onlyIfDirty) throws JSONException { public void write(JSONWriter jsonWriter, boolean onlyIfDirty)
throws JSONException {
if (!onlyIfDirty || isDirty()) { if (!onlyIfDirty || isDirty()) {
Properties options = new Properties(); Properties options = new Properties();
options.setProperty("mode", "save"); options.setProperty("mode", "save");
@ -219,8 +235,7 @@ public class ProjectMetadata implements Jsonizable {
if (obj.has("expressions") && !obj.isNull("expressions")) { // backward compatibility if (obj.has("expressions") && !obj.isNull("expressions")) { // backward compatibility
try { try {
((TopList) pm._preferenceStore.get("scripting.expressions")) ((TopList) pm._preferenceStore.get("scripting.expressions")).load(obj.getJSONArray("expressions"));
.load(obj.getJSONArray("expressions"));
} catch (JSONException e) { } catch (JSONException e) {
logger.error(ExceptionUtils.getFullStackTrace(e)); logger.error(ExceptionUtils.getFullStackTrace(e));
} }
@ -330,8 +345,7 @@ public class ProjectMetadata implements Jsonizable {
} }
public String[] getTags() { public String[] getTags() {
if (_tags == null) if (_tags == null) this._tags = new String[0];
this._tags = new String[0];
return _tags; return _tags;
} }
@ -383,67 +397,55 @@ public class ProjectMetadata implements Jsonizable {
updateModified(); updateModified();
} }
public String getCreator() { public String getCreator() {
return _creator; return _creator;
} }
public void setCreator(String creator) { public void setCreator(String creator) {
this._creator = creator; this._creator = creator;
updateModified(); updateModified();
} }
public String getContributors() { public String getContributors() {
return _contributors; return _contributors;
} }
public void setContributors(String contributors) { public void setContributors(String contributors) {
this._contributors = contributors; this._contributors = contributors;
updateModified(); updateModified();
} }
public String getSubject() { public String getSubject() {
return _subject; return _subject;
} }
public void setSubject(String subject) { public void setSubject(String subject) {
this._subject = subject; this._subject = subject;
updateModified(); updateModified();
} }
public String getDescription() { public String getDescription() {
return _description; return _description;
} }
public void setDescription(String description) { public void setDescription(String description) {
this._description = description; this._description = description;
updateModified(); updateModified();
} }
public int getRowCount() { public int getRowCount() {
return _rowCount; return _rowCount;
} }
public void setRowCount(int rowCount) { public void setRowCount(int rowCount) {
this._rowCount = rowCount; this._rowCount = rowCount;
updateModified(); updateModified();
} }
public JSONArray getUserMetadata() { public JSONArray getUserMetadata() {
return _userMetadata; return _userMetadata;
} }
public void setUserMetadata(JSONArray userMetadata) { public void setUserMetadata(JSONArray userMetadata) {
this._userMetadata = userMetadata; this._userMetadata = userMetadata;
} }
@ -465,8 +467,11 @@ public class ProjectMetadata implements Jsonizable {
Class<? extends ProjectMetadata> metaClass = this.getClass(); Class<? extends ProjectMetadata> metaClass = this.getClass();
try { try {
Field metaField = metaClass.getDeclaredField("_" + metaName); Field metaField = metaClass.getDeclaredField("_" + metaName);
if (metaName.equals("tags")) {
metaField.set(this, valueString.split(","));
} else {
metaField.set(this, valueString); metaField.set(this, valueString);
}
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException e) {
updateUserMetadata(metaName, valueString); updateUserMetadata(metaName, valueString);
} catch (SecurityException | IllegalArgumentException | IllegalAccessException e) { } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {

View File

@ -94,9 +94,15 @@ public class ProjectManagerTests extends RefineTest {
SUT.registerProject(project, metadata); SUT.registerProject(project, metadata);
<<<<<<< Upstream, based on origin/master
AssertProjectRegistered(); AssertProjectRegistered();
verify(metadata, times(1)).getTags(); verify(metadata, times(1)).getTags();
=======
AssertProjectRegistered();
verify(metadata, times(1)).getTags();
>>>>>>> 529b6bd Modified tags in metadata dialog and moved column right to name
verifyNoMoreInteractions(project); verifyNoMoreInteractions(project);
verifyNoMoreInteractions(metadata); verifyNoMoreInteractions(metadata);
} }
@ -121,7 +127,11 @@ public class ProjectManagerTests extends RefineTest {
this.verifySaveTimeCompared(1); this.verifySaveTimeCompared(1);
verify(SUT, times(1)).saveProject(project); verify(SUT, times(1)).saveProject(project);
verify(metadata, times(1)).getTags(); verify(metadata, times(1)).getTags();
<<<<<<< Upstream, based on origin/master
=======
>>>>>>> 529b6bd Modified tags in metadata dialog and moved column right to name
//ensure end //ensure end
verifyNoMoreInteractions(project); verifyNoMoreInteractions(project);
verifyNoMoreInteractions(metadata); verifyNoMoreInteractions(metadata);

View File

@ -31,7 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package com.google.refine.tests.model; package com.google.refine.tests.browsing.facets;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;

View File

@ -31,7 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package com.google.refine.tests.model; package com.google.refine.tests.operations.cell;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;

View File

@ -351,7 +351,14 @@ Refine.TagsManager._getAllProjectTags = function() {
}); });
array.map(function(item){ array.map(function(item){
<<<<<<< Upstream, based on origin/master
self.allProjectTags.push(item); self.allProjectTags.push(item);
=======
self.allProjectTags.push(item);
});
},
async : false
>>>>>>> 529b6bd Modified tags in metadata dialog and moved column right to name
}); });
}, },
async : false async : false

View File

@ -21,11 +21,38 @@ function EditMetadataDialog(metaData, targetRowElem) {
var td2 = tr.insertCell(2); var td2 = tr.insertCell(2);
if(key==="tags"){
$('<button class="button">').text($.i18n._('core-index')["edit"]).appendTo(td2).click(function() {
var oldTags = $(td1).text().replace("\"","").replace("[","").replace("]","");
oldTags = replaceAll(oldTags,"\"","");
var newTags = window.prompt($.i18n._('core-index')["change-metadata-value"]+" " + key, value);
newTags = newTags.replace("\"","").replace("[","").replace("]","");
newTags = replaceAll(newTags,"\"","");
if (newTags !== null) {
$(td1).text(newTags);
metaData[key] = newTags;
$.ajax({
type : "POST",
url : "command/core/set-project-tags",
data : {
"project" : project,
"old" : oldTags,
"new" : newTags
},
dataType : "json",
});
}
Refine.OpenProjectUI.refreshProject(targetRowElem, metaData);
});
}
if (key !== "created" && if (key !== "created" &&
key !== "modified" && key !== "modified" &&
key !== "rowCount" && key !== "rowCount" &&
key !== "importOptionMetadata" && key !== "importOptionMetadata" &&
key !== "id") { key !== "id" &&
key !== "tags") {
$('<button class="button">').text($.i18n._('core-index')["edit"]).appendTo(td2).click(function() { $('<button class="button">').text($.i18n._('core-index')["edit"]).appendTo(td2).click(function() {
var newValue = window.prompt($.i18n._('core-index')["change-metadata-value"]+" " + key, value); var newValue = window.prompt($.i18n._('core-index')["change-metadata-value"]+" " + key, value);
if (newValue !== null) { if (newValue !== null) {
@ -63,7 +90,7 @@ EditMetadataDialog.prototype._createDialog = function() {
this._level = DialogSystem.showDialog(frame); this._level = DialogSystem.showDialog(frame);
this._elmts.closeButton.html($.i18n._('core-buttons')["close"]); this._elmts.closeButton.html($.i18n._('core-buttons')["close"]);
this._elmts.closeButton.click(function() { self._dismiss(); }); this._elmts.closeButton.click(function() { self._dismiss();Refine.OpenProjectUI.prototype._addTagFilter()});
var body = $("#metadata-body"); var body = $("#metadata-body");
@ -111,3 +138,11 @@ EditMetadataDialog.prototype._dismiss = function() {
DialogSystem.dismissUntil(this._level - 1); DialogSystem.dismissUntil(this._level - 1);
}; };
function escapeRegExp(str) {
return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}
function replaceAll(str, find, replace) {
return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
}

View File

@ -192,11 +192,11 @@ Refine.OpenProjectUI.prototype._renderProjects = function(data) {
'<th></th>' + '<th></th>' +
'<th>'+$.i18n._('core-index-open')["last-mod"]+'</th>' + '<th>'+$.i18n._('core-index-open')["last-mod"]+'</th>' +
'<th>'+$.i18n._('core-index-open')["name"]+'</th>' + '<th>'+$.i18n._('core-index-open')["name"]+'</th>' +
'<th>'+$.i18n._('core-index-open')["tags"]+'</th>' +
'<th>'+$.i18n._('core-index-open')["creator"]+'</th>' + '<th>'+$.i18n._('core-index-open')["creator"]+'</th>' +
'<th>'+$.i18n._('core-index-open')["subject"]+'</th>' + '<th>'+$.i18n._('core-index-open')["subject"]+'</th>' +
'<th>'+$.i18n._('core-index-open')["description"]+'</th>' + '<th>'+$.i18n._('core-index-open')["description"]+'</th>' +
'<th>'+$.i18n._('core-index-open')["row-count"]+'</th>' + '<th>'+$.i18n._('core-index-open')["row-count"]+'</th>' +
'<th>'+$.i18n._('core-index-open')["tags"]+'</th>' +
(function() { (function() {
var htmlDisplay = ""; var htmlDisplay = "";
for (var n in data.customMetadataColumns) { for (var n in data.customMetadataColumns) {
@ -261,36 +261,18 @@ Refine.OpenProjectUI.prototype._renderProjects = function(data) {
.attr("href", "project?project=" + project.id) .attr("href", "project?project=" + project.id)
.appendTo($(tr.insertCell(tr.cells.length))); .appendTo($(tr.insertCell(tr.cells.length)));
var appendMetaField = function(data) {
$('<div></div>')
.html(data)
.appendTo($(tr.insertCell(tr.cells.length)));
};
appendMetaField(project.creator);
appendMetaField(project.subject);
appendMetaField(project.description, '20%');
appendMetaField(project.rowCount);
var data = project.userMetadata; var tagsCell = $(tr.insertCell(tr.cells.length));
for(var i in data)
{
if (data[i].display === true) {
appendMetaField(data[i].value);
}
}
$(tr.insertCell(tr.cells.length));
var tags = project.tags; var tags = project.tags;
for (var index = 0; index < tags.length; index++) { tags.map(function(tag){
var tag = tags[index];
$("<span/>") $("<span/>")
.addClass("project-tag") .addClass("project-tag")
.text(tag) .text(tag)
.attr("title", $.i18n._('core-index-open')["edit-tags"]) .attr("title", $.i18n._('core-index-open')["edit-tags"])
.appendTo($(tr.cells[tr.cells.length - 1])); .appendTo(tagsCell);
$(tr).addClass(tag); $(tr).addClass(tag);
} });
var editTagsLink = $('<a></a>') var editTagsLink = $('<a></a>')
@ -326,7 +308,26 @@ Refine.OpenProjectUI.prototype._renderProjects = function(data) {
} }
}); });
return false; return false;
}).appendTo($(tr.cells[tr.cells.length - 1])); }).appendTo(tagsCell);
var appendMetaField = function(data) {
$('<div></div>')
.html(data)
.appendTo($(tr.insertCell(tr.cells.length)));
};
appendMetaField(project.creator);
appendMetaField(project.subject);
appendMetaField(project.description, '20%');
appendMetaField(project.rowCount);
var data = project.userMetadata;
for(var i in data)
{
if (data[i].display === true) {
appendMetaField(data[i].value);
}
}
$(tr).mouseenter(function() { $(tr).mouseenter(function() {
editTagsLink.css("visibility", "visible"); editTagsLink.css("visibility", "visible");
@ -388,18 +389,113 @@ Refine.OpenProjectUI.prototype._onClickUploadFileButton = function(evt) {
}; };
Refine.OpenProjectUI.refreshProject = function(tr, metaData) { Refine.OpenProjectUI.refreshProject = function(tr, metaData) {
var refreshMetaField = function(data, index) { var refreshMetaField = function(data, index) {
if (index === 3) { if (index === 3) {
$('a', $('td', tr).eq(index)) $('a', $('td', tr).eq(index))
.text(data); .text(data);
} else { } else {
$('td', tr).eq(index) $('td', tr).eq(index).find('div')
.text(data); .text(data);
} }
}; };
var refreshMetaTags = function(data, index) {
var tagCol = $('td', tr).eq(index).empty();
if(data.constructor === Array){
data.map(function(tag){
var tagsCell = $("<span/>")
.addClass("project-tag")
.text(tag)
.attr("title", $.i18n._('core-index-open')["edit-tags"])
.appendTo(tagCol);
var editTagsLink = $('<a></a>')
.text($.i18n._('core-index-open')["rename"])
.addClass("secondary")
.addClass("edit-project-tags")
.css("visibility", "hidden")
.attr("href", "")
.attr("title", $.i18n._('core-index-open')["edit-tags"])
.html('<img src="images/edit.png" />')
.click(function() {
var oldTags = project.tags.join(",");
var newTags = window.prompt($.i18n._('core-index-open')["edit-tags-desc"],oldTags);
if (newTags === null || newTags === oldTags) {
return false;
}
$.ajax({
type : "POST",
url : "command/core/set-project-tags",
data : {
"project" : project.id,
"old" : oldTags,
"new" : newTags
},
dataType : "json",
success : function(data) {
if (data && typeof data.code != 'undefined' && data.code == "ok") {
Refine.TagsManager.allProjectTags = [];
self._buildTagsAndFetchProjects();
} else {
alert($.i18n._('core-index-open')["warning-tags-update"]+ " "+ data.message);
}
}
});
return false;
}).appendTo(tagCol);
tagCol.parent().addClass(tag);
});
} else{
data.split(",").map(function(tag){
var tagsCell = $("<span/>")
.addClass("project-tag")
.text(tag)
.attr("title", $.i18n._('core-index-open')["edit-tags"])
.appendTo(tagCol);
var editTagsLink = $('<a></a>')
.text($.i18n._('core-index-open')["rename"])
.addClass("secondary")
.addClass("edit-project-tags")
.css("visibility", "hidden")
.attr("href", "")
.attr("title", $.i18n._('core-index-open')["edit-tags"])
.html('<img src="images/edit.png" />')
.click(function() {
var oldTags = project.tags.join(",");
var newTags = window.prompt($.i18n._('core-index-open')["edit-tags-desc"],oldTags);
if (newTags === null || newTags === oldTags) {
return false;
}
$.ajax({
type : "POST",
url : "command/core/set-project-tags",
data : {
"project" : project.id,
"old" : oldTags,
"new" : newTags
},
dataType : "json",
success : function(data) {
if (data && typeof data.code != 'undefined' && data.code == "ok") {
Refine.TagsManager.allProjectTags = [];
self._buildTagsAndFetchProjects();
} else {
alert($.i18n._('core-index-open')["warning-tags-update"]+ " "+ data.message);
}
}
});
return false;
}).appendTo(tagCol);
tagCol.parent().addClass(tag);
});
}
};
var index = 3; var index = 3;
refreshMetaField(metaData.name, index); index++; refreshMetaField(metaData.name, index); index++;
refreshMetaTags(metaData.tags, index); index++;
refreshMetaField(metaData.creator, index); index++; refreshMetaField(metaData.creator, index); index++;
refreshMetaField(metaData.subject,index); index++; refreshMetaField(metaData.subject,index); index++;
refreshMetaField(metaData.description,index); index++; refreshMetaField(metaData.description,index); index++;
@ -428,6 +524,20 @@ Refine.OpenProjectUI.refreshProject = function(tr, metaData) {
} }
} }
Refine.TagsManager.allProjectTags = [];
var self = this;
var list = $("#tagsUl").empty();
self._allTags = Refine.TagsManager._getAllProjectTags();
var li = $('<li/>').addClass("active").appendTo(list);
$('<a/>').attr('href',
'#all').addClass("current").text('All').appendTo(li);
$.each(self._allTags, function(i) {
var li = $('<li/>').appendTo(list);
$('<a/>').attr('href', '#' + self._allTags[i]).text(self._allTags[i])
.appendTo(li);
});
}; };
Refine.actionAreas.push({ Refine.actionAreas.push({