From b21fd642a5ffa9db33d4af67c87c7e2f96ad5e79 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Wed, 23 May 2012 21:54:03 -0300 Subject: [PATCH] Start working on a folders support. --- .../wisemapping/rest/MindmapController.java | 10 +++- .../com/wisemapping/rest/MindmapFilter.java | 56 +++++++++++++++++++ wise-webapp/src/main/webapp/css/mymaps.less | 12 ++++ wise-webapp/src/main/webapp/js/mymaps.js | 40 +++++++++++++ .../src/main/webapp/jsp/mindmapList.jsp | 36 +++++++----- 5 files changed, 136 insertions(+), 18 deletions(-) create mode 100644 wise-webapp/src/main/java/com/wisemapping/rest/MindmapFilter.java diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java index d1d5ea94..2d2012c6 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java @@ -41,15 +41,19 @@ public class MindmapController extends BaseController { } @RequestMapping(method = RequestMethod.GET, value = "/maps", produces = {"application/json", "text/html", "application/xml"}) - public ModelAndView getMindmaps() throws IOException { + public ModelAndView getMindmaps(@RequestParam(required = false) String q) throws IOException { final User user = com.wisemapping.security.Utils.getUser(); + final MindmapFilter filter = MindmapFilter.parse(q); + final List mapsByUser = mindmapService.getMindmapUserByUser(user); final List mindmaps = new ArrayList(); for (MindmapUser mindmapUser : mapsByUser) { - mindmaps.add(mindmapUser.getMindMap()); + final MindMap mindmap = mindmapUser.getMindMap(); + if (filter.accept(mindmap, user)) { + mindmaps.add(mindmap); + } } - final RestMindmapList restMindmapList = new RestMindmapList(mindmaps); return new ModelAndView("mapsView", "list", restMindmapList); } diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapFilter.java b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapFilter.java new file mode 100644 index 00000000..435a3ab1 --- /dev/null +++ b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapFilter.java @@ -0,0 +1,56 @@ +package com.wisemapping.rest; + + +import com.wisemapping.model.MindMap; +import com.wisemapping.model.User; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public enum MindmapFilter { + ALL("all") { + @Override + public boolean accept(@NotNull MindMap mindmap, @NotNull User user) { + return true; + } + + }, + MY_MAPS("my_maps") { + @Override + boolean accept(@NotNull MindMap mindmap, @NotNull User user) { + return mindmap.getOwner().equals(user); + } + }, + SHARED_WITH_ME("shared_with_me") { + @Override + boolean accept(@NotNull MindMap mindmap, @NotNull User user) { + return !MY_MAPS.accept(mindmap, user); + } + }, + PUBLIC("public") { + @Override + boolean accept(@NotNull MindMap mindmap, @NotNull User user) { + return mindmap.isPublic(); + } + }; + + private String id; + + MindmapFilter(@NotNull String id) { + this.id = id; + } + + static public MindmapFilter parse(@Nullable String valueStr) { + MindmapFilter result = ALL; + final MindmapFilter[] values = MindmapFilter.values(); + for (MindmapFilter value : values) { + if (value.id.equals(valueStr)) { + result = value; + break; + } + } + return result; + } + + abstract boolean accept(@NotNull MindMap mindmap, @NotNull User user); + +} \ No newline at end of file diff --git a/wise-webapp/src/main/webapp/css/mymaps.less b/wise-webapp/src/main/webapp/css/mymaps.less index 88b81561..999bad7d 100644 --- a/wise-webapp/src/main/webapp/css/mymaps.less +++ b/wise-webapp/src/main/webapp/css/mymaps.less @@ -85,6 +85,11 @@ input#selectAll { .dataTables_filter { float:right; } + +#mindmapListTable th { + padding: 4px; +} + /* Pagination Styles */ #paginateContainer { height:40px; @@ -162,3 +167,10 @@ input#selectAll { height:50px; white-space:nowrap; } + +#foldersContainer { + width: 15%; + float: left; + margin-right: 2%; + margin-top: 80px +} diff --git a/wise-webapp/src/main/webapp/js/mymaps.js b/wise-webapp/src/main/webapp/js/mymaps.js index 6d02c0c3..9dd60bfa 100644 --- a/wise-webapp/src/main/webapp/js/mymaps.js +++ b/wise-webapp/src/main/webapp/js/mymaps.js @@ -18,6 +18,46 @@ jQuery.fn.dataTableExt.oSort['es_date-desc'] = function(a, b) { return ((x < y) ? 1 : ((x > y) ? -1 : 0)); }; +$.fn.dataTableExt.oApi.fnReloadAjax = function (oSettings, sNewSource, fnCallback, bStandingRedraw) { + if (typeof sNewSource != 'undefined' && sNewSource != null) { + oSettings.sAjaxSource = sNewSource; + } + this.oApi._fnProcessingDisplay(oSettings, true); + var that = this; + var iStart = oSettings._iDisplayStart; + var aData = []; + + this.oApi._fnServerParams(oSettings, aData); + + oSettings.fnServerData(oSettings.sAjaxSource, aData, function(json) { + /* Clear the old information from the table */ + that.oApi._fnClearTable(oSettings); + + /* Got the data - add it to the table */ + var aData = (oSettings.sAjaxDataProp !== "") ? + that.oApi._fnGetObjectDataFn(oSettings.sAjaxDataProp)(json) : json; + + for (var i = 0; i < aData.length; i++) { + that.oApi._fnAddData(oSettings, aData[i]); + } + + oSettings.aiDisplay = oSettings.aiDisplayMaster.slice(); + that.fnDraw(); + + if (typeof bStandingRedraw != 'undefined' && bStandingRedraw === true) { + oSettings._iDisplayStart = iStart; + that.fnDraw(false); + } + + that.oApi._fnProcessingDisplay(oSettings, false); + + /* Callback user function - for event handlers etc */ + if (typeof fnCallback == 'function' && fnCallback != null) { + fnCallback(oSettings); + } + }, oSettings); +} + jQuery.fn.dataTableExt.selectAllMaps = function() { var total = $('.select input:checkbox[id!="selectAll"]').size(); var selected = $('.select input:checked[id!="selectAll"]').size(); diff --git a/wise-webapp/src/main/webapp/jsp/mindmapList.jsp b/wise-webapp/src/main/webapp/jsp/mindmapList.jsp index f3a41b20..3ccfc16f 100644 --- a/wise-webapp/src/main/webapp/jsp/mindmapList.jsp +++ b/wise-webapp/src/main/webapp/jsp/mindmapList.jsp @@ -52,12 +52,6 @@ return '' + obj.aData.title + ''; } }, - { - bVisible: false, - bSearchable : false, - sTitle : "Owner Email", - mDataProp: "ownerEmail" - }, { sTitle : "Owner", mDataProp :"owner" @@ -78,7 +72,7 @@ oLanguage : { "sSearch" : "", "sInfo" : "_START_-_END_ of _TOTAL_", - "sEmptyTable": "Hey, you don't have any mindmap. Go ahead and create one clicking on the 'New' button !!!" + "sEmptyTable": "No mindmap available for the selected filter criteria." }, bStateSave:true }); @@ -233,12 +227,24 @@ $("#actionButtons .tagMap").click(function() { }); - $("#actionButtons .share").click(function() { - }); - $("#actionButtons .tags").click(function() { }); + + $('#foldersContainer li').click(function(event) { + // Deselect previous option ... + $('#foldersContainer li').removeClass('active'); + $('#foldersContainer i').removeClass('icon-white'); + + // Select the new item ... + var dataTable = $('#mindmapListTable').dataTable(); + $(this).addClass('active').filter('i').addClass('icon-white'); + + // Reload the table data ... + dataTable.fnReloadAjax("../service/maps?q=" + $(this).attr('data-filter')); + + event.preventDefault(); + }); }); // Register time update functions .... @@ -265,13 +271,13 @@