Skip to content

Commit

Permalink
#3004 Fix Cancel functionality on File Tags Popups
Browse files Browse the repository at this point in the history
  • Loading branch information
sekmiller committed Mar 18, 2016
1 parent 4d65294 commit 6f02f7e
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 50 deletions.
36 changes: 20 additions & 16 deletions src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -3563,16 +3563,9 @@ public void setTabFileTagsByName(List<String> tabFileTagsByName) {
}

private void refreshCategoriesByName(){

categoriesByName= new ArrayList<>();
for (FileMetadata fm : selectedFiles) {
if (fm.getCategories() != null) {
for (int i = 0; i < fm.getCategories().size(); i++) {
if (!categoriesByName.contains(fm.getCategories().get(i).getName())) {
categoriesByName.add(fm.getCategories().get(i).getName());
}
}
}
for (String category: dataset.getCategoriesByName() ){
categoriesByName.add(category);
}
refreshSelectedTags();
}
Expand Down Expand Up @@ -3684,9 +3677,6 @@ public void setNewCategoryName(String newCategoryName) {
public String saveNewCategory() {
if (newCategoryName != null && !newCategoryName.isEmpty()) {
categoriesByName.add(newCategoryName);
for (FileMetadata fm : selectedFiles) {
fm.addCategoryByName(newCategoryName);
}
}
//Now increase size of selectedTags and add new category
String[] temp = new String[selectedTags.length + 1];
Expand All @@ -3701,10 +3691,24 @@ public String saveNewCategory() {
private void refreshSelectedTags() {
selectedTags = null;
selectedTags = new String[0];
if (categoriesByName.size() > 0) {
selectedTags = new String[categoriesByName.size()];
for (int i = 0; i < categoriesByName.size(); i++) {
selectedTags[i] = categoriesByName.get(i);

List selectedCategoriesByName= new ArrayList<>();
for (FileMetadata fm : selectedFiles) {
if (fm.getCategories() != null) {
for (int i = 0; i < fm.getCategories().size(); i++) {
if (!selectedCategoriesByName.contains(fm.getCategories().get(i).getName())) {
selectedCategoriesByName.add(fm.getCategories().get(i).getName());
}

}

}
}

if (selectedCategoriesByName.size() > 0) {
selectedTags = new String[selectedCategoriesByName.size()];
for (int i = 0; i < selectedCategoriesByName.size(); i++) {
selectedTags[i] = (String) selectedCategoriesByName.get(i);
}
}
Arrays.sort(selectedTags);
Expand Down
91 changes: 65 additions & 26 deletions src/main/java/edu/harvard/iq/dataverse/EditDatafilesPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,16 @@ public List<String> getTabFileTags() {
public void setTabFileTags(List<String> tabFileTags) {
this.tabFileTags = tabFileTags;
}

private String[] selectedTabFileTags = {};

public String[] getSelectedTabFileTags() {
return selectedTabFileTags;
}

public void setSelectedTabFileTags(String[] selectedTabFileTags) {
this.selectedTabFileTags = selectedTabFileTags;
}

private String[] selectedTags = {};

Expand Down Expand Up @@ -1536,27 +1546,26 @@ private void refreshTabFileTagsByName() {
}

private void refreshSelectedTabFileTags() {
selectedTags = null;
selectedTags = new String[0];
selectedTabFileTags = null;
selectedTabFileTags = new String[0];
if (tabFileTagsByName.size() > 0) {
selectedTags = new String[tabFileTagsByName.size()];
selectedTabFileTags = new String[tabFileTagsByName.size()];
for (int i = 0; i < tabFileTagsByName.size(); i++) {
selectedTags[i] = tabFileTagsByName.get(i);
selectedTabFileTags[i] = tabFileTagsByName.get(i);
}
}
Arrays.sort(selectedTags);
Arrays.sort(selectedTabFileTags);
}

private void refreshCategoriesByName() {
categoriesByName = new ArrayList<>();
if (fileMetadataSelectedForTagsPopup.getCategories() != null) {
for (int i = 0; i < fileMetadataSelectedForTagsPopup.getCategories().size(); i++) {
categoriesByName.add(fileMetadataSelectedForTagsPopup.getCategories().get(i).getName());
}
private void refreshCategoriesByName(){
categoriesByName= new ArrayList<>();
for (String category: dataset.getCategoriesByName() ){
categoriesByName.add(category);
}
refreshSelectedTags();
}


private List<String> categoriesByName;

public List<String> getCategoriesByName() {
Expand All @@ -1570,10 +1579,20 @@ public void setCategoriesByName(List<String> categoriesByName) {
private void refreshSelectedTags() {
selectedTags = null;
selectedTags = new String[0];
if (categoriesByName.size() > 0) {
selectedTags = new String[categoriesByName.size()];
for (int i = 0; i < categoriesByName.size(); i++) {
selectedTags[i] = categoriesByName.get(i);
List selectedCategoriesByName = new ArrayList<>();

if (fileMetadataSelectedForTagsPopup.getCategories() != null) {
for (int i = 0; i < fileMetadataSelectedForTagsPopup.getCategories().size(); i++) {
if (!selectedCategoriesByName.contains(fileMetadataSelectedForTagsPopup.getCategories().get(i).getName())) {
selectedCategoriesByName.add(fileMetadataSelectedForTagsPopup.getCategories().get(i).getName());
}
}
}

if (selectedCategoriesByName.size() > 0) {
selectedTags = new String[selectedCategoriesByName.size()];
for (int i = 0; i < selectedCategoriesByName.size(); i++) {
selectedTags[i] = (String) selectedCategoriesByName.get(i);
}
}
Arrays.sort(selectedTags);
Expand All @@ -1586,6 +1605,8 @@ public String[] getSelectedTags() {
public void setSelectedTags(String[] selectedTags) {
this.selectedTags = selectedTags;
}



/*
* "File Tags" (aka "File Categories"):
Expand All @@ -1600,12 +1621,18 @@ public String getNewCategoryName() {
public void setNewCategoryName(String newCategoryName) {
this.newCategoryName = newCategoryName;
}

public String saveNewCategory() {

if (newCategoryName != null && !newCategoryName.isEmpty()) {
fileMetadataSelectedForTagsPopup.addCategoryByName(newCategoryName);
}
categoriesByName.add(newCategoryName);
}
//Now increase size of selectedTags and add new category
String[] temp = new String[selectedTags.length + 1];
System.arraycopy(selectedTags, 0, temp, 0, selectedTags.length);
selectedTags = temp;
selectedTags[selectedTags.length - 1] = newCategoryName;
//Blank out added category
newCategoryName = "";
return "";
}
Expand All @@ -1615,12 +1642,24 @@ public String saveNewCategory() {
*/
public void saveFileTagsAndCategories() {
// 1. File categories:
// we don't need to do anything for the file categories that the user
// selected from the pull down list; that was done directly from the
// page with the FileMetadata.setCategoriesByName() method.
// So here we only need to take care of the new, custom category
// name, if entered:
/*
In order to get the cancel button to work we had to separate the selected tags
from the file metadata and re-add them on save
*/

fileMetadataSelectedForTagsPopup.setCategories(new ArrayList());
if (newCategoryName != null) {
fileMetadataSelectedForTagsPopup.addCategoryByName(newCategoryName);
}
// 2. Tabular DataFile Tags:
if (selectedTags != null) {
for (int i = 0; i < selectedTags.length; i++) {
fileMetadataSelectedForTagsPopup.addCategoryByName(selectedTags[i]);
}
}


logger.fine("New category name: " + newCategoryName);

if (fileMetadataSelectedForTagsPopup != null && newCategoryName != null) {
Expand All @@ -1633,14 +1672,14 @@ public void saveFileTagsAndCategories() {

// 2. Tabular DataFile Tags:

if (tabularDataTagsUpdated && selectedTags != null) {
if (tabularDataTagsUpdated && selectedTabFileTags != null) {
if (fileMetadataSelectedForTagsPopup != null && fileMetadataSelectedForTagsPopup.getDataFile() != null) {
fileMetadataSelectedForTagsPopup.getDataFile().setTags(null);
for (int i = 0; i < selectedTags.length; i++) {
for (int i = 0; i < selectedTabFileTags.length; i++) {

DataFileTag tag = new DataFileTag();
try {
tag.setTypeByLabel(selectedTags[i]);
tag.setTypeByLabel(selectedTabFileTags[i]);
tag.setDataFile(fileMetadataSelectedForTagsPopup.getDataFile());
fileMetadataSelectedForTagsPopup.getDataFile().addTag(tag);

Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/dataset.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@
<p:ajax event="toggleSelect" listener="#{DatasetPage.handleSelection}" update="selectedTagsList" />
<p:ajax event="change" listener="#{DatasetPage.handleSelection}" update="selectedTagsList" />

<f:selectItems value="#{DatasetPage.dataset.categoriesByName}"/>
<f:selectItems value="#{DatasetPage.categoriesByName}"/>
</p:selectCheckboxMenu>
<p:message for="fileTagsMenuDS" display="text" />
</div>
Expand Down
15 changes: 8 additions & 7 deletions src/main/webapp/editFilesFragment.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
selection="#{EditDatafilesPage.selectedFiles}" var="fileMetadata" widgetVar="filesTable"
emptyMessage="#{datasetPage || EditDatafilesPage.showFileUploadFileComponent() ? bundle['file.noUploadedFiles.tip'] : bundle['file.noSelectedFiles.tip']}">
<f:facet name="header">
#{datasetPage}
<div jsf:id="filesHeaderBlock" class="row">
<h:inputHidden id="showAccessPopup" value="#{EditDatafilesPage.showAccessPopup}"/>
<div id="filesHeaderCount" class="col-xs-6 text-left">
Expand Down Expand Up @@ -471,12 +472,12 @@
</label>
<div class="col-sm-8">
<p:outputPanel id="selectedTagsListEFF" style="padding-top:.5em;">
<h:outputText value="#{bundle['file.editTagsDialog.selectedTags.none']}" rendered="#{(empty EditDatafilesPage.selectedTags) and (empty EditDatafilesPage.fileMetadataSelectedForTagsPopup.categoriesByName)}" />
<h:outputText value="#{bundle['file.editTagsDialog.selectedTags.none']}" rendered="#{(empty EditDatafilesPage.selectedTags) and (empty EditDatafilesPage.selectedTabFileTags)}" />

<ui:repeat value="#{EditDatafilesPage.fileMetadataSelectedForTagsPopup.categoriesByName}" var="tags" rendered="#{!empty EditDatafilesPage.fileMetadataSelectedForTagsPopup.categoriesByName}">
<ui:repeat value="#{EditDatafilesPage.selectedTags}" var="tags" rendered="#{!empty EditDatafilesPage.selectedTags}">
<h:outputText value="#{tags}" styleClass="label label-default" style="margin-right:.5em;display:inline-block;"/>
</ui:repeat>
<ui:repeat value="#{EditDatafilesPage.selectedTags}" var="tags" rendered="#{!empty EditDatafilesPage.selectedTags}">
<ui:repeat value="#{EditDatafilesPage.selectedTabFileTags}" var="tags" rendered="#{!empty EditDatafilesPage.selectedTabFileTags}">
<h:outputText value="#{tags}" styleClass="label label-info" style="margin-right:.5em;display:inline-block;"/>
</ui:repeat>
</p:outputPanel>
Expand All @@ -488,8 +489,8 @@
</label>
<div class="col-sm-8">
<p:selectCheckboxMenu id="fileTagsMenu" styleClass="form-control"
value="#{EditDatafilesPage.fileMetadataSelectedForTagsPopup.categoriesByName}" label="#{bundle.select}">
<f:selectItems value="#{EditDatafilesPage.fileMetadataSelectedForTagsPopup.datasetVersion.dataset.categoriesByName}"/>
value="#{EditDatafilesPage.selectedTags}" label="#{bundle.select}">
<f:selectItems value="#{EditDatafilesPage.categoriesByName}"/>
<p:ajax event="toggleSelect" listener="#{EditDatafilesPage.handleSelection}" update="selectedTagsListEFF" />
<p:ajax event="change" listener="#{EditDatafilesPage.handleSelection}" update="selectedTagsListEFF" />
</p:selectCheckboxMenu>
Expand Down Expand Up @@ -523,7 +524,7 @@
<div class="col-sm-8">
<p class="help-block">#{bundle['file.tabularDataTags.tip']}</p>
<p:selectCheckboxMenu id="tabularDataTags" styleClass="form-control"
value="#{EditDatafilesPage.selectedTags}" label="#{bundle.select}"
value="#{EditDatafilesPage.selectedTabFileTags}" label="#{bundle.select}"
filter="false">
<f:selectItems value="#{EditDatafilesPage.tabFileTags}" />
<p:ajax event="toggleSelect" listener="#{EditDatafilesPage.handleSelection}" update="selectedTagsListEFF" />
Expand All @@ -544,7 +545,7 @@
</div>
<div class="button-block">
<p:commandButton styleClass="btn btn-default" id="editFileTagsPopupSaveButton" value="#{bundle.saveChanges}" oncomplete="PF('editFileTagsPopup').hide()" update=":datasetForm:filesTable" actionListener="#{EditDatafilesPage.saveFileTagsAndCategories()}"/>
<p:commandButton styleClass="btn btn-default" id="editFileTagsPopupCancelButton" value="#{bundle.cancel}" onclick="PF('editFileTagsPopup').hide();PF('blockFileForm').hide();" actionListener="#{EditDatafilesPage.clearFileMetadataSelectedForTagsPopup()}"/>
<p:commandButton styleClass="btn btn-default" id="editFileTagsPopupCancelButton" value="#{bundle.cancel}" onclick="PF('editFileTagsPopup').hide();PF('blockFileForm').hide();" update=":datasetForm:filesTable" actionListener="#{EditDatafilesPage.clearFileMetadataSelectedForTagsPopup()}"/>
</div>
</p:dialog>
<script type="text/javascript" src="/resources/js/dropins.js" id="dropboxjs" data-app-key="#{EditDatafilesPage.dropBoxKey}"/>
Expand Down

0 comments on commit 6f02f7e

Please sign in to comment.