Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
First cut of a maven completer, need to handle URI prefixes and figur…
…e out why typeahead and dialogs don't mix well
  • Loading branch information
gashcrumb committed Jul 31, 2013
1 parent 1f2ecae commit 355e873
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 3 deletions.
2 changes: 1 addition & 1 deletion hawtio-web/src/main/webapp/app/fabric/html/profile.html
Expand Up @@ -69,7 +69,7 @@ <h2 style="display: inline;">/ <a ng-href="#/fabric/view?cv={{versionId}}&sp={{r
{{feature}}
</li>
<li>
<i class="clickable icon-edit" ng-click="newFileDialog = true" title="Edit features"></i>
<i class="clickable icon-edit" ng-click="goto('/fabric/profile/{{versionId}}/{{profileId}}/editFeatures')" title="Edit features"></i>
</li>
</ul>
</dd>
Expand Down
11 changes: 11 additions & 0 deletions hawtio-web/src/main/webapp/app/fabric/html/test.html
@@ -1,5 +1,16 @@
<div ng-controller="Fabric.TestController">

<div class="row-fluid">
<div class="span3">
<p>Model: {{someUri}}</p>
<p>uriParts</p>
<ol>
<li ng-repeat="part in uriParts">{{part}}</li>
</ol>
<input class="input-xlarge" type="text" ng-model="someUri" typeahead="name for name in doCompletion($viewValue) | filter:$viewValue" typeahead-min-length="3" typeahead-on-select="onSelectCallback($item, $model, $label)">
</div>
</div>

<div class="row-fluid">
<div class="span3">
<div fabric-profile-selector='osp' version-id='vid' included-profiles="someProfiles"></div>
Expand Down
9 changes: 8 additions & 1 deletion hawtio-web/src/main/webapp/app/fabric/js/profile.ts
@@ -1,8 +1,11 @@
module Fabric {

export function ProfileController($scope, $routeParams, jolokia, $location, workspace:Workspace) {
export function ProfileController($scope, $routeParams, jolokia, $location, workspace:Workspace, $q) {

Fabric.initScope($scope, workspace);

$scope.mavenMBean = Maven.getMavenIndexerMBean(workspace);

$scope.versionId = $routeParams.versionId;
$scope.profileId = $routeParams.profileId;

Expand All @@ -25,6 +28,10 @@ module Fabric {
}


$scope.goto = (location) => {
$location.url(location);
}

$scope.addNewThing = (title, type, current) => {
$scope.thingName = title;
$scope.currentThing = current;
Expand Down
37 changes: 36 additions & 1 deletion hawtio-web/src/main/webapp/app/fabric/js/test.ts
@@ -1,9 +1,13 @@
module Fabric {

export function TestController($scope, jolokia) {
export function TestController($scope, jolokia, $q, workspace) {

$scope.mavenMBean = Maven.getMavenIndexerMBean(workspace);

$scope.version = {};
$scope.versionId = '';
$scope.someUri = '';
$scope.uriParts = [];

$scope.osp = [];
$scope.vid = '1.0';
Expand All @@ -29,6 +33,37 @@ module Fabric {

});

$scope.$watch('someUri', (newValue, oldValue) => {
if (newValue !== oldValue) {
$scope.uriParts = newValue.split("/");
}
});

$scope.$watch('uriParts', (newValue, oldValue) => {
if (newValue !== oldValue) {
console.log("oldValue: ", oldValue);
console.log("newValue: ", newValue);

if (newValue.length === 1 && newValue.length < oldValue.length) {
if (oldValue.last() !== '' && newValue.first().has(oldValue.last())) {
var merged = oldValue.first(oldValue.length - 1).include(newValue.first());
$scope.someUri = merged.join('/');
}
}
}
}, true);

$scope.onSelectCallback = ($item, $model, $label) => {
//$scope.uriParts.push($model);
//$scope.someUri = $scope.uriParts.join("/");
//console.log('item=', $item, 'model=', $model, 'label=', $label);
}

$scope.doCompletion = (something) => {
return Maven.completeMavenUri($q, $scope, workspace, jolokia, something);
}





Expand Down
120 changes: 120 additions & 0 deletions hawtio-web/src/main/webapp/app/maven/js/helpers.ts
Expand Up @@ -32,6 +32,126 @@ module Maven {
return id;
}


export function completeMavenUri($q, $scope, workspace, jolokia, query) {

var mbean = getMavenIndexerMBean(workspace);

if (mbean === null) {
return $q.when([]);
}

var parts = query.split('/');
if (parts.length === 1) {
// still searching the groupId
return Maven.completeGroupId($q, $scope, workspace, jolokia, query, null, null);
}
if (parts.length === 2) {
// have the groupId, guess we're looking for the artifactId
return Maven.completeArtifactId($q, $scope, workspace, jolokia, parts[0], parts[1], null, null);
}
if (parts.length === 3) {
// guess we're searching for the version
return Maven.completeVersion($q, $scope, workspace, jolokia, parts[0], parts[1], parts[2], null, null);
}

return $q.when([]);
}


export function completeVersion($q, $scope, workspace, jolokia, groupId, artifactId, partial, packaging, classifier) {

/*
if (partial.length < 5) {
return $q.when([]);
}
*/

var deferred = $q.defer();

jolokia.request({
type: 'exec',
mbean: getMavenIndexerMBean(workspace),
operation: 'versionComplete(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)',
arguments: [groupId, artifactId, partial, packaging, classifier]
}, {
method: 'POST',
success: (response) => {
$scope.$apply(() => {
deferred.resolve(response.value.sortBy().first(15));
});
},
error: (response) => {
$scope.$apply(() => {
console.log("got back an error: ", response);
deferred.reject();
});
}
});

return deferred.promise;

}

export function completeArtifactId($q, $scope, workspace, jolokia, groupId, partial, packaging, classifier) {

var deferred = $q.defer();

jolokia.request({
type: 'exec',
mbean: getMavenIndexerMBean(workspace),
operation: 'artifactIdComplete(java.lang.String, java.lang.String, java.lang.String, java.lang.String)',
arguments: [groupId, partial, packaging, classifier]
}, {
method: 'POST',
success: (response) => {
$scope.$apply(() => {
deferred.resolve(response.value.sortBy().first(15));
});
},
error: (response) => {
$scope.$apply(() => {
console.log("got back an error: ", response);
deferred.reject();
});
}
});

return deferred.promise;
}

export function completeGroupId($q, $scope, workspace, jolokia, partial, packaging, classifier) {

// let's go easy on the indexer
if (partial.length < 5) {
return $q.when([]);
}

var deferred = $q.defer();

jolokia.request({
type: 'exec',
mbean: getMavenIndexerMBean(workspace),
operation: 'groupIdComplete(java.lang.String, java.lang.String, java.lang.String)',
arguments: [partial, packaging, classifier]
}, {
method: 'POST',
success: (response) => {
$scope.$apply(() => {
deferred.resolve(response.value.sortBy().first(15));
});
},
error: (response) => {
console.log("got back an error: ", response);
$scope.$apply(() => {
deferred.reject();
});
}
});

return deferred.promise;
}

export function addMavenFunctions($scope, workspace) {
$scope.detailLink = (row) => {
var group = row.groupId;
Expand Down

0 comments on commit 355e873

Please sign in to comment.