From 783b7b34635b58470e888d32745c7241fd48f298 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 3 Sep 2011 12:13:02 +0200 Subject: [PATCH 1/8] added basic repository search --- .../js/repository/sonia.repository.grid.js | 9 ++++ .../js/repository/sonia.repository.panel.js | 46 +++++++++++++++---- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js index e2d17d9bb1..1a759ba8ff 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js @@ -97,6 +97,15 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, { p.doLayout(); this.ownerCt.doLayout(); }, + + search: function(value){ + value = value.toLowerCase(); + this.getStore().filterBy(function(rec){ + return ! value || + rec.get('name').toLowerCase().indexOf(value) >= 0 || + rec.get('description').toLowerCase().indexOf(value) >= 0; + }); + }, selectItem: function(item){ if ( debug ){ diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js index 8bd68a6d02..d382a2d0d2 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js @@ -44,15 +44,41 @@ Sonia.repository.Panel = Ext.extend(Sonia.rest.Panel, { var toolbar = []; if ( admin ){ - toolbar.push( - {xtype: 'tbbutton', text: this.addText, icon: this.addIcon, scope: this, handler: this.showAddForm} - ); + toolbar.push({ + xtype: 'tbbutton', + text: this.addText, + icon: this.addIcon, + scope: this, + handler: this.showAddForm + }); } - toolbar.push( - {xtype: 'tbbutton', id: 'repoRmButton', disabled: true, text: this.removeText, icon: this.removeIcon, scope: this, handler: this.removeRepository}, - '-', - {xtype: 'tbbutton', text: this.reloadText, icon: this.reloadIcon, scope: this, handler: this.reload} - ); + toolbar.push({ + xtype: 'tbbutton', + id: 'repoRmButton', + disabled: true, + text: this.removeText, + icon: this.removeIcon, + scope: this, + handler: this.removeRepository + },'-', { + xtype: 'tbbutton', + text: this.reloadText, + icon: this.reloadIcon, + scope: this, + handler: this.reload + },'-',{ + xtype: 'label', + text: 'Search: ' + }, ' ',{ + xtype: 'textfield', + enableKeyEvents: true, + listeners: { + keyup: { + fn: this.search, + scope: this + } + } + }); var config = { tbar: toolbar, @@ -81,6 +107,10 @@ Sonia.repository.Panel = Ext.extend(Sonia.rest.Panel, { Ext.apply(this, Ext.apply(this.initialConfig, config)); Sonia.repository.Panel.superclass.initComponent.apply(this, arguments); }, + + search: function(field){ + Ext.getCmp('repositoryGrid').search(field.getValue()); + }, removeRepository: function(){ var grid = Ext.getCmp('repositoryGrid'); From a6b2122ef6f61ac78502cd892a372cb75965a9f5 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 3 Sep 2011 14:59:15 +0200 Subject: [PATCH 2/8] improve repository search --- .../js/repository/sonia.repository.grid.js | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js index 1a759ba8ff..b699503737 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js @@ -39,6 +39,8 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, { colUrlText: 'Url', emptyText: 'No repository is configured', formTitleText: 'Repository Form', + + searchValue: null, initComponent: function(){ @@ -51,6 +53,12 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, { fields: [ 'id', 'name', 'type', 'contact', 'description', 'creationDate', 'url', 'public', 'permissions', 'properties' ], sortInfo: { field: 'name' + }, + listeners: { + load: { + fn: this.storeLoad, + scope: this + } } }); @@ -86,6 +94,12 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, { Ext.apply(this, Ext.apply(this.initialConfig, config)); Sonia.repository.Grid.superclass.initComponent.apply(this, arguments); }, + + storeLoad: function(store){ + if (this.searchValue){ + this.searchStore(store); + } + }, onFallBelowMinHeight: function(height, minHeight){ var p = Ext.getCmp('repositoryEditPanel'); @@ -99,8 +113,18 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, { }, search: function(value){ - value = value.toLowerCase(); - this.getStore().filterBy(function(rec){ + this.searchValue = value; + var store = this.getStore(); + if ( ! value ){ + store.clearFilter(); + } else { + this.searchStore(store); + } + }, + + searchStore: function(store){ + var value = this.searchValue.toLowerCase(); + store.filterBy(function(rec){ return ! value || rec.get('name').toLowerCase().indexOf(value) >= 0 || rec.get('description').toLowerCase().indexOf(value) >= 0; From b109ab33b9f5dcf2aa69a32a96b78e93b0c961b6 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 3 Sep 2011 15:26:41 +0200 Subject: [PATCH 3/8] added repository type filter --- .../js/repository/sonia.repository.grid.js | 42 ++++++++++++------- .../js/repository/sonia.repository.panel.js | 33 ++++++++++++++- 2 files changed, 57 insertions(+), 18 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js index b699503737..7c64d482ca 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js @@ -41,6 +41,7 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, { formTitleText: 'Repository Form', searchValue: null, + typeFilter: null, initComponent: function(){ @@ -95,9 +96,9 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, { Sonia.repository.Grid.superclass.initComponent.apply(this, arguments); }, - storeLoad: function(store){ + storeLoad: function(){ if (this.searchValue){ - this.searchStore(store); + this.filterStore(); } }, @@ -113,22 +114,31 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, { }, search: function(value){ - this.searchValue = value; - var store = this.getStore(); - if ( ! value ){ - store.clearFilter(); - } else { - this.searchStore(store); - } + this.searchValue = value; + this.filterStore(); }, - searchStore: function(store){ - var value = this.searchValue.toLowerCase(); - store.filterBy(function(rec){ - return ! value || - rec.get('name').toLowerCase().indexOf(value) >= 0 || - rec.get('description').toLowerCase().indexOf(value) >= 0; - }); + filter: function(type){ + this.typeFilter = type; + this.filterStore(); + }, + + filterStore: function(){ + var store = this.getStore(); + if ( ! this.searchValue && ! this.typeFilter ){ + store.clearFilter(); + } else { + var search = null; + if ( this.searchValue ){ + search = this.searchValue.toLowerCase(); + } + store.filterBy(function(rec){ + return (! search || + rec.get('name').toLowerCase().indexOf(search) >= 0 || + rec.get('description').toLowerCase().indexOf(search) >= 0) && + (! this.typeFilter || rec.get('type') == this.typeFilter); + }, this); + } }, selectItem: function(item){ diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js index d382a2d0d2..ce597cc65e 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js @@ -67,9 +67,30 @@ Sonia.repository.Panel = Ext.extend(Sonia.rest.Panel, { scope: this, handler: this.reload },'-',{ + xtype: 'label', + text: 'Filter: ' + }, ' ', { + xtype: 'combo', + hiddenName : 'type', + typeAhead: true, + triggerAction: 'all', + lazyRender: true, + mode: 'local', + editable: false, + store: repositoryTypeStore, + valueField: 'name', + displayField: 'displayName', + allowBlank: true, + listeners: { + select: { + fn: this.filterByType, + scope: this + } + } + }, ' ',{ xtype: 'label', text: 'Search: ' - }, ' ',{ + }, ' ',{ xtype: 'textfield', enableKeyEvents: true, listeners: { @@ -77,7 +98,7 @@ Sonia.repository.Panel = Ext.extend(Sonia.rest.Panel, { fn: this.search, scope: this } - } + } }); var config = { @@ -108,6 +129,14 @@ Sonia.repository.Panel = Ext.extend(Sonia.rest.Panel, { Sonia.repository.Panel.superclass.initComponent.apply(this, arguments); }, + filterByType: function(combo, rec){ + var name = rec.get('name'); + + console.debug(name); + + Ext.getCmp('repositoryGrid').filter(name); + }, + search: function(field){ Ext.getCmp('repositoryGrid').search(field.getValue()); }, From 648a034e3f7838724a8bb7f8fc58caeabcd6c3d4 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 3 Sep 2011 15:32:36 +0200 Subject: [PATCH 4/8] remove debug info --- .../resources/js/repository/sonia.repository.panel.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js index ce597cc65e..a7d4b11e0b 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js @@ -130,11 +130,7 @@ Sonia.repository.Panel = Ext.extend(Sonia.rest.Panel, { }, filterByType: function(combo, rec){ - var name = rec.get('name'); - - console.debug(name); - - Ext.getCmp('repositoryGrid').filter(name); + Ext.getCmp('repositoryGrid').filter(rec.get('name')); }, search: function(field){ From 43962eb508f80835d1b30b442932587957c2314d Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 3 Sep 2011 15:48:29 +0200 Subject: [PATCH 5/8] added empty item to combobox to clear filter --- .../js/repository/sonia.repository.panel.js | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js index a7d4b11e0b..59fde09254 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js @@ -42,6 +42,23 @@ Sonia.repository.Panel = Ext.extend(Sonia.rest.Panel, { initComponent: function(){ + // create new store for repository types + var typeStore = new Ext.data.JsonStore({ + id: 1, + fields: [ 'displayName', 'name' ] + }); + + // load types from server state + typeStore.loadData(state.repositoryTypes); + + // add empty value + var t = new typeStore.recordType({ + displayName: '', + name: '' + }); + + typeStore.insert(0, t); + var toolbar = []; if ( admin ){ toolbar.push({ @@ -77,7 +94,7 @@ Sonia.repository.Panel = Ext.extend(Sonia.rest.Panel, { lazyRender: true, mode: 'local', editable: false, - store: repositoryTypeStore, + store: typeStore, valueField: 'name', displayField: 'displayName', allowBlank: true, @@ -86,7 +103,11 @@ Sonia.repository.Panel = Ext.extend(Sonia.rest.Panel, { fn: this.filterByType, scope: this } - } + }, + tpl:'' + + '
' + + '{displayName} ' + + '
' }, ' ',{ xtype: 'label', text: 'Search: ' From f81ab4f5d1badb878e5b36d8ae7c85f44115ccdd Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Mon, 5 Sep 2011 11:49:23 +0200 Subject: [PATCH 6/8] clear filter after repository creation, see #48 --- .../js/repository/sonia.repository.grid.js | 7 +++++++ .../js/repository/sonia.repository.panel.js | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js index 7c64d482ca..f8fe3a6212 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.grid.js @@ -123,6 +123,13 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, { this.filterStore(); }, + clearStoreFilter: function(){ + this.searchValue = null; + this.typeFilter = null; + this.getStore().clearFilter(); + }, + + filterStore: function(){ var store = this.getStore(); if ( ! this.searchValue && ! this.typeFilter ){ diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js index 59fde09254..948b4c5840 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js @@ -87,6 +87,7 @@ Sonia.repository.Panel = Ext.extend(Sonia.rest.Panel, { xtype: 'label', text: 'Filter: ' }, ' ', { + id: 'repositoryTypeFilter', xtype: 'combo', hiddenName : 'type', typeAhead: true, @@ -112,6 +113,7 @@ Sonia.repository.Panel = Ext.extend(Sonia.rest.Panel, { xtype: 'label', text: 'Search: ' }, ' ',{ + id: 'repositorySearch', xtype: 'textfield', enableKeyEvents: true, listeners: { @@ -218,12 +220,24 @@ Sonia.repository.Panel = Ext.extend(Sonia.rest.Panel, { scope: this }, created: { - fn: this.reload, + fn: this.clearRepositoryFilter, scope: this } } }]); }, + + clearRepositoryFilter: function(){ + if (debug){ + console.debug('clear repository filter'); + } + Ext.getCmp('repositorySearch').setValue(''); + Ext.getCmp('repositoryTypeFilter').setValue(''); + var grid = Ext.getCmp('repositoryGrid'); + grid.clearStoreFilter(); + grid.reload(); + + }, reload: function(){ Ext.getCmp('repositoryGrid').reload(); From c64d47d0a51ee05c887f3938adda35407a27a68c Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Mon, 5 Sep 2011 12:23:59 +0200 Subject: [PATCH 7/8] select new repository after creation --- .../repository/sonia.repository.formpanel.js | 18 ++++++++++++++- .../js/repository/sonia.repository.panel.js | 22 ++++++++++++++----- .../resources/js/rest/sonia.rest.grid.js | 21 +++++++++++++----- 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.formpanel.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.formpanel.js index 016b0d9526..cb8055528e 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.formpanel.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.formpanel.js @@ -99,6 +99,16 @@ Sonia.repository.FormPanel = Ext.extend(Sonia.rest.FormPanel,{ } }); }, + + getIdFromResponse: function(response){ + var id = null; + var location = response.getResponseHeader('Location') + if (location){ + var parts = location.split('/'); + id = parts[parts.length - 1]; + } + return id; + }, create: function(item){ if ( debug ){ @@ -115,10 +125,16 @@ Sonia.repository.FormPanel = Ext.extend(Sonia.rest.FormPanel,{ jsonData: item, method: 'POST', scope: this, - success: function(){ + success: function(response){ if ( debug ){ console.debug('create success'); } + + var id = this.getIdFromResponse(response); + if (id){ + item.id = id; + } + this.fireEvent('created', item); this.getForm().reset(); clearTimeout(tid); diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js index 948b4c5840..ffe4eb9e9b 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.panel.js @@ -220,23 +220,35 @@ Sonia.repository.Panel = Ext.extend(Sonia.rest.Panel, { scope: this }, created: { - fn: this.clearRepositoryFilter, + fn: this.repositoryCreated, scope: this } } }]); }, - clearRepositoryFilter: function(){ + repositoryCreated: function(item){ + var grid = Ext.getCmp('repositoryGrid'); + this.clearRepositoryFilter(grid); + + grid.reload(function(){ + if (debug){ + console.debug('select repository ' + item.id + " after creation"); + } + grid.selectById(item.id); + }); + }, + + clearRepositoryFilter: function(grid){ if (debug){ console.debug('clear repository filter'); } + if (! grid ){ + grid = Ext.getCmp('repositoryGrid'); + } Ext.getCmp('repositorySearch').setValue(''); Ext.getCmp('repositoryTypeFilter').setValue(''); - var grid = Ext.getCmp('repositoryGrid'); grid.clearStoreFilter(); - grid.reload(); - }, reload: function(){ diff --git a/scm-webapp/src/main/webapp/resources/js/rest/sonia.rest.grid.js b/scm-webapp/src/main/webapp/resources/js/rest/sonia.rest.grid.js index eac88095ad..d8b45475ef 100644 --- a/scm-webapp/src/main/webapp/resources/js/rest/sonia.rest.grid.js +++ b/scm-webapp/src/main/webapp/resources/js/rest/sonia.rest.grid.js @@ -87,11 +87,14 @@ Sonia.rest.Grid = Ext.extend(Ext.grid.GridPanel, { Sonia.rest.Grid.superclass.onDestroy.apply(this, arguments); }, - reload: function(){ + reload: function(callback, scope){ if ( debug ){ console.debug('reload store'); } - this.store.load(); + this.store.load({ + callback: callback, + scope: scope + }); }, selectionChanged: function(sm){ @@ -131,12 +134,18 @@ Sonia.rest.Grid = Ext.extend(Ext.grid.GridPanel, { return String.format( this.checkboxTemplate, param ); }, + selectById: function(id){ + var index = this.getStore().indexOfId(id); + if ( index >= 0 ){ + this.getSelectionModel().selectRow(index); + } else if (debug) { + console.debug('could not find item with id ' + id); + } + }, + handleHistory: function(params){ if (params && params.length > 0){ - var index = this.getStore().indexOfId(params[0]); - if ( index >= 0 ){ - this.getSelectionModel().selectRow(index); - } + this.selectById(params[0]) } else { if (debug){ console.debug( 'clear selection' ); From 5dde6d973f824193696e2115e5e8aa9c1f826564 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Mon, 5 Sep 2011 13:43:43 +0200 Subject: [PATCH 8/8] close branch issue-48