Skip to content

Commit

Permalink
Merge pull request #40 from lyft/revert-38-revert-37-LYFT-27661-histo…
Browse files Browse the repository at this point in the history
…ry-workflow

Revert "Revert "Add a history view and revert workflow""
  • Loading branch information
ryan-lane committed Apr 6, 2015
2 parents 8ed04aa + 373947d commit ab22410
Show file tree
Hide file tree
Showing 32 changed files with 730 additions and 58 deletions.
1 change: 0 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"browser": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
Expand Down
44 changes: 19 additions & 25 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
// Generated on 2014-11-03 using generator-angular 0.9.8
'use strict';

// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'

module.exports = function (grunt) {

// Load grunt tasks automatically
Expand Down Expand Up @@ -36,19 +30,19 @@ module.exports = function (grunt) {
tasks: ['bower:install', 'wiredep', 'symlink', 'compass:app']
},
js: {
files: ['<%= project.app %>/modules/{,*/}*.js'],
files: ['<%= project.app %>/modules/**/*.js'],
tasks: ['newer:jshint:all']
},
jsTest: {
files: ['<%= project.app %>/modules/**/*.js'],
tasks: ['test']
},
styles: {
files: ['<%= project.app %>/styles/{,*/}*.css'],
files: ['<%= project.app %>/styles/**/*.css'],
tasks: ['newer:copy:styles']
},
compass: {
files: ['<%= project.app %>/{modules,styles}/{,*/}*.{scss,sass}'],
files: ['<%= project.app %>/{modules,styles}/**/*.{scss,sass}'],
tasks: ['compass:app']
},
gruntfile: {
Expand Down Expand Up @@ -136,14 +130,14 @@ module.exports = function (grunt) {
all: {
src: [
'Gruntfile.js',
'<%= project.app %>/modules/{,*/}*.js'
'<%= project.app %>/modules/**/*.js'
]
},
test: {
options: {
jshintrc: 'test/.jshintrc'
},
src: ['test/spec/{,*/}*.js']
src: ['test/spec/**/*.js']
}
},

Expand Down Expand Up @@ -171,22 +165,22 @@ module.exports = function (grunt) {
},
scripts: {
src: [
'<%= project.app %>/js/{,*}/*.js',
'<%= project.app %>/js/**/*.js',
'<%= project.app %>/modules/**/*.js'
]
},
styles: {
src: ['<%= project.app %>/styles/{,*/}*.css']
src: ['<%= project.app %>/styles/**/*.css']
}
},

// Renames files for browser caching purposes
filerev: {
dist: {
src: [
'<%= project.dist %>/scripts/{,*/}*.js',
'<%= project.dist %>/styles/{,*/}*.css',
'<%= project.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
'<%= project.dist %>/scripts/**/*.js',
'<%= project.dist %>/styles/**/*.css',
'<%= project.dist %>/images/**/*.{png,jpg,jpeg,gif,webp,svg}',
'<%= project.dist %>/styles/fonts/*'
]
}
Expand All @@ -200,8 +194,8 @@ module.exports = function (grunt) {
},
src: [
'<%= project.dist %>/index.html',
'<%= project.dist %>/styles/{,*/}*.css',
'<%= project.dist %>/scripts/{,*/}*.js'
'<%= project.dist %>/styles/**/*.css',
'<%= project.dist %>/scripts/**/*.js'
]
}
},
Expand All @@ -228,8 +222,8 @@ module.exports = function (grunt) {

// Performs rewrites based on filerev and the useminPrepare configuration
usemin: {
html: ['<%= project.dist %>/{,*/}*.html'],
css: ['<%= project.dist %>/styles/{,*/}*.css'],
html: ['<%= project.dist %>/**/*.html'],
css: ['<%= project.dist %>/styles/**/*.css'],
options: {
assetsDirs: ['<%= project.dist %>','<%= project.dist %>/images']
}
Expand All @@ -243,7 +237,7 @@ module.exports = function (grunt) {
// dist: {
// files: {
// '<%= project.dist %>/styles/main.css': [
// '.tmp/styles/{,*/}*.css'
// '.tmp/styles/**/*.css'
// ]
// }
// }
Expand All @@ -266,7 +260,7 @@ module.exports = function (grunt) {
files: [{
expand: true,
cwd: '<%= project.app %>/images',
src: '{,*/}*.{png,jpg,jpeg,gif}',
src: '**/*.{png,jpg,jpeg,gif}',
dest: '<%= project.dist %>/images'
}]
}
Expand All @@ -277,7 +271,7 @@ module.exports = function (grunt) {
files: [{
expand: true,
cwd: '<%= project.app %>/images',
src: '{,*/}*.svg',
src: '**/*.svg',
dest: '<%= project.dist %>/images'
}]
}
Expand Down Expand Up @@ -332,7 +326,7 @@ module.exports = function (grunt) {
src: [
'*.{ico,png,txt}',
'*.html',
'images/{,*/}*.{webp}',
'images/**/*.{webp}',
'fonts/*'
]
}, {
Expand All @@ -351,7 +345,7 @@ module.exports = function (grunt) {
expand: true,
cwd: '<%= project.app %>/styles',
dest: '.tmp/styles/',
src: '{,*/}*.css'
src: '**/*.css'
}
},

Expand Down
10 changes: 10 additions & 0 deletions confidant/models/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ class Meta:
modified_date = UTCDateTimeAttribute(range_key=True)


class DataTypeRevisionIndex(GlobalSecondaryIndex):
class Meta:
projection = AllProjection()
read_capacity_units = 10
write_capacity_units = 10
data_type = UnicodeAttribute(hash_key=True)
revision = NumberAttribute(range_key=True)


class Service(Model):
class Meta:
table_name = app.config.get('DYNAMODB_TABLE')
Expand All @@ -28,6 +37,7 @@ class Meta:
id = UnicodeAttribute(hash_key=True)
data_type = UnicodeAttribute()
data_type_date_index = DataTypeDateIndex()
data_type_revision_index = DataTypeRevisionIndex()
revision = NumberAttribute()
credentials = UnicodeSetAttribute()
modified_date = UTCDateTimeAttribute(default=datetime.now)
Expand Down
13 changes: 10 additions & 3 deletions confidant/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ <h1>Confidant</h1>

<div class="container-fluid container-bottomborder" role="navigation" ng-controller="common.NavCtrl">
<ul class="nav nav-pills">
<li role="presentation" ng-class="{ active: viewLocation == 'resources'}"><a href="#/resources">Resources <span class="icon-lock"></span></a></li>
<!--<li role="presentation" ng-class="{ active: viewLocation == 'history'}"><a href="#/history">History<span class="icon-scroll"></span></a></li>-->
<li role="presentation" ng-class="{ active: viewLocation == 'admin'}"><a href="#/admin">Admin <span class="icon-settings"></span></a></li>
<li role="presentation" ng-class="{ 'active': viewLocation === 'resources' }"><a href="#/resources">Resources <span class="icon-lock"></span></a></li>
<li role="presentation" ng-class="{ 'active': viewLocation === 'history' }"><a href="#/history">History <span class="icon-clock"></span></a></li>
<li role="presentation" ng-class="{ 'active': viewLocation === 'admin' }"><a href="#/admin">Admin <span class="icon-settings"></span></a></li>
</ul>
</div>
<div ui-view="main" class="container-fluid container-body"></div>
Expand Down Expand Up @@ -96,6 +96,13 @@ <h1>Confidant</h1>
<script src="/modules/common/services/services.js"></script>
<script src="/modules/common/services/spin-on.js"></script>
<script src="/modules/common/services/userinfo.js"></script>
<script src="/modules/history/controllers/CredentialHistoryCtrl.js"></script>
<script src="/modules/history/controllers/ResourceHistoryCtrl.js"></script>
<script src="/modules/history/controllers/ServiceHistoryCtrl.js"></script>
<script src="/modules/history/controllers/controllers.js"></script>
<script src="/modules/history/history.js"></script>
<script src="/modules/history/services/archive.js"></script>
<script src="/modules/history/services/services.js"></script>
<script src="/modules/resources/controllers/CredentialDetailsCtrl.js"></script>
<script src="/modules/resources/controllers/ResourceCtrl.js"></script>
<script src="/modules/resources/controllers/ServiceDetailsCtrl.js"></script>
Expand Down
6 changes: 3 additions & 3 deletions confidant/public/modules/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function(angular) {
'use strict';

var confidantApp = angular.module('confidantApp', [
angular.module('confidantApp', [
// external libs
'ngAnimate',
'ngCookies',
Expand All @@ -14,8 +14,8 @@
// local dependencies
'confidant.common',

// load routes
'confidant.routes'
// load routes
'confidant.routes'
])

/*
Expand Down
2 changes: 2 additions & 0 deletions confidant/public/modules/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
SERVICE: 'v1/services/:id',
SERVICES: 'v1/services',
ARCHIVE_SERVICES: 'v1/archive/services',
ARCHIVE_SERVICE_REVISIONS: 'v1/archive/services/:id/:revision',
CREDENTIAL: 'v1/credentials/:id',
CREDENTIALS: 'v1/credentials',
ARCHIVE_CREDENTIALS: 'v1/archive/credentials',
ARCHIVE_CREDENTIAL_REVISIONS: 'v1/archive/credentials/:id/:revision',
PROFILES: 'v1/profiles'
})

Expand Down
6 changes: 6 additions & 0 deletions confidant/public/modules/common/controllers/NavCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
$scope.viewLocation = newViewLocation;
}
});
$scope.getHistoryView = NavService.getHistoryView;
$scope.$watch('getHistoryView()', function(newHistoryView, oldHistoryView) {
if(newHistoryView !== oldHistoryView) {
$scope.historyView = newHistoryView;
}
});
}])

;
Expand Down
6 changes: 6 additions & 0 deletions confidant/public/modules/common/services/NavService.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@
function($rootScope) {
var _this = this;
this.viewLocation = '';
this.historyView = '';
$rootScope.$on('$stateChangeSuccess', function(evt, state) {
if(state.data) {
_this.viewLocation = state.data.viewLocation;
_this.historyView = state.data.historyView;
}
});

this.getViewLocation = function() {
return _this.viewLocation;
};

this.getHistoryView = function() {
return _this.historyView;
};

}])

;
Expand Down
2 changes: 1 addition & 1 deletion confidant/public/modules/common/services/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Keep this list sorted alphabetically!
'confidant.common.services.http',
'confidant.common.services.NavService',
'confidant.common.services.SpinOn',
'confidant.common.services.SpinOn',
'confidant.common.services.userinfo'
])
;
Expand Down
103 changes: 103 additions & 0 deletions confidant/public/modules/history/controllers/CredentialHistoryCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
(function(angular) {
'use strict';

angular.module('confidant.history.controllers.CredentialHistoryCtrl', [
'ui.router',
'ngResource',
'xeditable',
'confidant.resources.services',
'confidant.history.services'
])


.controller('history.CredentialHistoryCtrl', [
'$scope',
'$stateParams',
'$filter',
'$q',
'$log',
'$location',
'credentials.credential',
'credentials.archiveCredentialRevisions',
'history.ResourceArchiveService',
function ($scope, $stateParams, $filter, $q, $log, $location, Credential, CredentialArchiveRevisions, ResourceArchiveService) {
function doQuery(credential, id) {
var d = $q.defer(),
result = credential.get({'id': id}, function() { d.resolve(result); });
return d.promise;
}

$scope.$log = $log;
$scope.revisions = [];

var idArr = $stateParams.credentialId.split('-');
$scope.credentialId = idArr[0];
$scope.credentialRevision = parseInt(idArr[1], 10);
CredentialArchiveRevisions.get({'id': $scope.credentialId}).$promise.then(function(revisions) {
$scope.revisions = $filter('orderBy')(revisions.revisions, 'revision', true);
$scope.currentRevision = parseInt($scope.revisions[0].revision, 10);
$scope.isOnlyRevision = false;
$scope.isCurrentRevision = false;
if ($scope.currentRevision === 1) {
$scope.isOnlyRevision = true;
$scope.diffRevision = $scope.currentRevision;
Credential.get({'id': $stateParams.credentialId}).$promise.then(function(credential) {
$scope.currentCredential = credential;
$scope.diffCredential = credential;
}, function() {
$scope.currentCredential = null;
$scope.diffCredential = null;
});
} else {
if ($scope.credentialRevision === $scope.currentRevision) {
$scope.diffRevision = $scope.currentRevision - 1;
} else {
$scope.diffRevision = $scope.credentialRevision;
}
var currentCredentialPromise = doQuery(Credential, $scope.credentialId + '-' + $scope.currentRevision),
diffCredentialPromise = doQuery(Credential, $scope.credentialId + '-' + $scope.diffRevision);
$q.all([currentCredentialPromise, diffCredentialPromise]).then(function(results) {
$scope.currentCredential = results[0];
$scope.diffCredential = results[1];
}, function() {
$scope.currentCredential = null;
$scope.diffCredential = null;
});
}
if ($scope.currentRevision === $scope.credentialRevision) {
$scope.isCurrentRevision = true;
}
});

$scope.revertToDiffRevision = function() {
var deferred = $q.defer();
if (angular.equals($scope.diffCredential.name, $scope.currentCredential.name) &&
angular.equals($scope.diffCredential.credential_pairs, $scope.currentCredential.credential_pairs)) {
$scope.saveError = 'Can not revert to revision ' + $scope.diffCredential.revision + '. No difference between it and current revision.';
deferred.reject();
return deferred.promise;
}
Credential.update({'id': $scope.credentialId}, $scope.diffCredential).$promise.then(function(newCredential) {
deferred.resolve();
ResourceArchiveService.updateResourceArchive();
$location.path('/history/credential/' + newCredential.id + '-' + newCredential.revision);
}, function(res) {
if (res.status === 500) {
$scope.saveError = 'Unexpected server error.';
$log.error(res);
} else {
$scope.saveError = res.data.error;
if ('conflicts' in res.data) {
$scope.credentialPairConflicts = res.data.conflicts;
}
}
deferred.reject();
});
return deferred.promise;
};

}])

;

})(window.angular);
Loading

0 comments on commit ab22410

Please sign in to comment.