Skip to content

Commit

Permalink
update the wiki so that it can be used to view / edit branches such a…
Browse files Browse the repository at this point in the history
…s if working with the fabric profile git repo
  • Loading branch information
jstrachan committed May 17, 2013
1 parent 170c387 commit 428fd59
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 30 deletions.
Expand Up @@ -123,11 +123,13 @@ module Dashboard {
constructor(public git:Git.GitRepository) {
}

public branch: string = null;

public putDashboards(array:Dashboard[], commitMessage:string, fn) {
angular.forEach(array, (dash) => {
var path = this.getDashboardPath(dash);
var contents = JSON.stringify(dash, null, " ");
this.git.write(path, commitMessage, contents, fn);
this.git.write(this.branch, path, commitMessage, contents, fn);
});
}

Expand All @@ -153,13 +155,13 @@ module Dashboard {
// TODO lets look in each team directory as well and combine the results...
var path = this.getUserDashboardDirectory();
var dashboards = [];
this.git.read(path, (details) => {
this.git.read(this.branch, path, (details) => {
var files = details.children;
// we now have all the files we need; lets read all their contents
angular.forEach(files, (file, idx) => {
var path = file.path;
if (!file.directory && path.endsWith(".json")) {
this.git.read(path, (details) => {
this.git.read(this.branch, path, (details) => {
// lets parse the contents
var content = details.text;
if (content) {
Expand All @@ -183,7 +185,7 @@ module Dashboard {

public getDashboard(id:string, fn) {
var path = this.getUserDashboardPath(id);
this.git.read(path, (details) => {
this.git.read(this.branch, path, (details) => {
var dashboard = null;
var content = details.text;
if (content) {
Expand Down
10 changes: 5 additions & 5 deletions hawtio-web/src/main/webapp/app/git/js/git.ts
Expand Up @@ -9,12 +9,12 @@ module Git {
* Read the contents of a file or directory
* with text or children being returned and a directory flag
*/
read(path:string, fn): void;
read(branch:string, path:string, fn): void;

/**
* Write the content of a file
*/
write(path:string, commitMessage:string, contents:string, fn): void;
write(branch:string, path:string, commitMessage:string, contents:string, fn): void;

/**
* Reverts to a specific version of the file
Expand Down Expand Up @@ -66,11 +66,11 @@ module Git {
constructor(public mbean:string, public jolokia, public localStorage, public branch = "master") {
}

public read(path:string, fn) {
this.jolokia.execute(this.mbean, "read", this.branch, path, onSuccess(fn));
public read(branch:string, path:string, fn) {
this.jolokia.execute(this.mbean, "read", branch, path, onSuccess(fn));
}

public write(path:string, commitMessage:string, contents:string, fn) {
public write(branch:string, path:string, commitMessage:string, contents:string, fn) {
var authorName = this.getUserName();
var authorEmail = this.getUserEmail();

Expand Down
6 changes: 4 additions & 2 deletions hawtio-web/src/main/webapp/app/wiki/js/camel.ts
Expand Up @@ -3,6 +3,8 @@ module Wiki {
export function CamelController($scope, $location, $routeParams, workspace:Workspace, wikiRepository:GitWikiRepository) {
$scope.schema = _apacheCamelModel;

Wiki.initScope($scope, $routeParams, $location);

var routeModel = _apacheCamelModel.definitions.route;
routeModel["_id"] = "route";

Expand Down Expand Up @@ -102,7 +104,7 @@ module Wiki {
if (text) {
// lets save the file...
var commitMessage = $scope.commitMessage || "Updated page " + $scope.pageId;
wikiRepository.putPage($scope.pageId, text, commitMessage, (status) => {
wikiRepository.putPage($scope.branch, $scope.pageId, text, commitMessage, (status) => {
Wiki.onComplete(status);
goToView();
Core.$apply($scope);
Expand Down Expand Up @@ -285,7 +287,7 @@ module Wiki {
];

if (Git.getGitMBean(workspace)) {
$scope.git = wikiRepository.getPage($scope.pageId, $scope.objectId, onResults);
$scope.git = wikiRepository.getPage($scope.branch, $scope.pageId, $scope.objectId, onResults);
}
}

Expand Down
11 changes: 5 additions & 6 deletions hawtio-web/src/main/webapp/app/wiki/js/edit.ts
@@ -1,8 +1,7 @@
module Wiki {
export function EditController($scope, $location, $routeParams, fileExtensionTypeRegistry, wikiRepository:GitWikiRepository) {

$scope.pageId = Wiki.pageId($routeParams, $location);
$scope.objectId = $routeParams["objectId"];
Wiki.initScope($scope, $routeParams, $location);
$scope.entity = {
source: null
};
Expand Down Expand Up @@ -30,7 +29,7 @@ module Wiki {
};

$scope.save = () => {
saveTo($scope.pageId);
saveTo($scope["pageId"]);
};

$scope.create = () => {
Expand Down Expand Up @@ -67,7 +66,7 @@ module Wiki {
if (isCreate()) {
updateSourceView();
} else {
wikiRepository.getPage($scope.pageId, $scope.objectId, onFileContents);
wikiRepository.getPage($scope.branch, $scope.pageId, $scope.objectId, onFileContents);
}
}

Expand All @@ -91,7 +90,7 @@ module Wiki {
if (form === "/") {
onFormSchema(_jsonSchema);
} else {
$scope.git = wikiRepository.getPage(form, $scope.objectId, (details) => {
$scope.git = wikiRepository.getPage($scope.branch, form, $scope.objectId, (details) => {
onFormSchema(Wiki.parseJson(details.text));
});
}
Expand Down Expand Up @@ -123,7 +122,7 @@ module Wiki {
contents = JSON.stringify($scope.formEntity, null, " ");
}
//console.log("About to write contents '" + contents + "'");
wikiRepository.putPage(path, contents, commitMessage, (status) => {
wikiRepository.putPage($scope.branch, path, contents, commitMessage, (status) => {
Wiki.onComplete(status);
goToView();
Core.$apply($scope);
Expand Down
4 changes: 2 additions & 2 deletions hawtio-web/src/main/webapp/app/wiki/js/formTable.ts
@@ -1,7 +1,7 @@
module Wiki {

export function FormTableController($scope, $location, $routeParams, workspace:Workspace, wikiRepository:GitWikiRepository) {
$scope.pageId = Wiki.pageId($routeParams, $location);
Wiki.initScope($scope, $routeParams, $location);
$scope.columnDefs = [];

$scope.viewLink = (row) => {
Expand Down Expand Up @@ -37,7 +37,7 @@ module Wiki {

var form = $location.search()["form"];
if (form) {
wikiRepository.getPage(form, $scope.objectId, onFormData);
wikiRepository.getPage($scope.branch, form, $scope.objectId, onFormData);
}

updateView();
Expand Down
11 changes: 11 additions & 0 deletions hawtio-web/src/main/webapp/app/wiki/js/helpers.ts
Expand Up @@ -81,6 +81,16 @@ module Wiki {
}


/**
* Extracts the pageId, branch, objectId from the route parameters
*/
export function initScope($scope, $routeParams, $location) {
$scope.pageId = Wiki.pageId($routeParams, $location);
$scope.branch = $routeParams["branch"] || $location.search()["branch"];
$scope.objectId = $routeParams["objectId"];
}


/**
* Extracts the pageId from the route parameters
*/
Expand All @@ -98,6 +108,7 @@ module Wiki {
}
} else break;
}
return pageId || "/";
}

// if no $routeParams variables lets figure it out from the $location
Expand Down
10 changes: 4 additions & 6 deletions hawtio-web/src/main/webapp/app/wiki/js/view.ts
@@ -1,9 +1,7 @@
module Wiki {

export function ViewController($scope, $location, $routeParams, workspace:Workspace, marked, fileExtensionTypeRegistry, wikiRepository:GitWikiRepository, $compile) {

$scope.pageId = Wiki.pageId($routeParams, $location);
$scope.objectId = $routeParams["objectId"];
Wiki.initScope($scope, $routeParams, $location);

$scope.gridOptions = {
data: 'children',
Expand Down Expand Up @@ -112,7 +110,7 @@ module Wiki {
var baseObjectId = $routeParams["baseObjectId"];
$scope.git = wikiRepository.diff($scope.objectId, baseObjectId, $scope.pageId, onFileDetails);
} else {
$scope.git = wikiRepository.getPage($scope.pageId, $scope.objectId, onFileDetails);
$scope.git = wikiRepository.getPage($scope.branch, $scope.pageId, $scope.objectId, onFileDetails);
}
}

Expand All @@ -138,7 +136,7 @@ module Wiki {
if (form === "/") {
onFormSchema(_jsonSchema);
} else {
$scope.git = wikiRepository.getPage(form, $scope.objectId, (details) => {
$scope.git = wikiRepository.getPage($scope.branch, form, $scope.objectId, (details) => {
onFormSchema(Wiki.parseJson(details.text));
});
}
Expand Down Expand Up @@ -189,7 +187,7 @@ module Wiki {
if (item) {
var pageName = item.path;
$scope.readMePath = pageName;
wikiRepository.getPage(pageName, $scope.objectId, (readmeDetails) => {
wikiRepository.getPage($scope.branch, pageName, $scope.objectId, (readmeDetails) => {
viewContents(pageName, readmeDetails.text);
});
}
Expand Down
2 changes: 2 additions & 0 deletions hawtio-web/src/main/webapp/app/wiki/js/wikiPlugin.ts
Expand Up @@ -11,6 +11,8 @@ module Wiki {
when('/wiki/diff/*page/:objectId/:baseObjectId', {templateUrl: 'app/wiki/html/viewPage.html'}).
when('/wiki/create/*page', {templateUrl: 'app/wiki/html/createPage.html'}).
when('/wiki/edit/*page', {templateUrl: 'app/wiki/html/editPage.html'}).
when('/wiki/branch/:branch/view/*page', {templateUrl: 'app/wiki/html/viewPage.html'}).
when('/wiki/branch/:branch/edit/*page', {templateUrl: 'app/wiki/html/editPage.html'}).
when('/wiki/history/*page', {templateUrl: 'app/wiki/html/history.html'});
}).
factory('wikiRepository',function (workspace:Workspace, jolokia, localStorage) {
Expand Down
10 changes: 5 additions & 5 deletions hawtio-web/src/main/webapp/app/wiki/js/wikiRepository.ts
@@ -1,7 +1,7 @@
module Wiki {

export interface WikiRepository {
putPage(path:string, contents:string, commitMessage:string, fn): void;
putPage(branch:string, path:string, contents:string, commitMessage:string, fn): void;

deletePage(path:string, fn): void;
}
Expand All @@ -12,7 +12,7 @@ module Wiki {
constructor(public factoryMethod:() => Git.GitRepository) {
}

public getPage(path:string, objectId:string, fn) {
public getPage(branch:string, path:string, objectId:string, fn) {
var git = this.git();
path = path || "/";
if (git) {
Expand All @@ -28,7 +28,7 @@ module Wiki {
});
} else {
var fullPath = this.getPath(path);
git.read(fullPath, (details) => {
git.read(branch, fullPath, (details) => {

// lets fix up any paths to be relative to the wiki
var children = details.children;
Expand Down Expand Up @@ -68,9 +68,9 @@ module Wiki {
return git;
}

public putPage(path:string, contents:string, commitMessage:string, fn) {
public putPage(branch:string, path:string, contents:string, commitMessage:string, fn) {
var fullPath = this.getPath(path);
this.git().write(fullPath, commitMessage, contents, fn);
this.git().write(branch, fullPath, commitMessage, contents, fn);
}

public revertTo(objectId:string, blobPath:string, commitMessage:string, fn) {
Expand Down

0 comments on commit 428fd59

Please sign in to comment.