-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#12 Add custom field create/update dialog to admin section
- Loading branch information
Showing
11 changed files
with
186 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
ui/app/scripts/controllers/admin/AdminCustomFieldDialogCtrl.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
(function() { | ||
'use strict'; | ||
|
||
angular.module('theHiveControllers').controller('AdminCustomFieldDialogCtrl', | ||
function($scope, $uibModalInstance, ListSrv, NotificationSrv, customField) { | ||
var self = this; | ||
self.reference = { | ||
types: ['string', 'number', 'boolean', 'date'] | ||
}; | ||
|
||
self.customField = customField; | ||
self.customField.options = (customField.options || []).join('\n'); | ||
|
||
var onSuccess = function(data) { | ||
$uibModalInstance.close(data); | ||
}; | ||
|
||
var onFailure = function(response) { | ||
NotificationSrv.error('AdminCustomFieldDialogCtrl', response.data, response.status); | ||
}; | ||
|
||
self.saveField = function() { | ||
var postData = _.pick(self.customField, 'name', 'title', 'label', 'description', 'type'); | ||
postData.options = _.isArray(self.customField.options) ? self.customField.options : self.customField.options.split('\n'); | ||
|
||
if(self.customField.id) { | ||
ListSrv.update( | ||
{'itemId': self.customField.id}, | ||
{'value': JSON.stringify(postData)}, | ||
onSuccess, | ||
onFailure); | ||
} else { | ||
ListSrv.save( | ||
{'listId': 'custom_fields'}, | ||
{'value': JSON.stringify(postData)}, | ||
onSuccess, | ||
onFailure); | ||
} | ||
}; | ||
|
||
self.cancel = function() { | ||
$uibModalInstance.dismiss(); | ||
} | ||
|
||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,10 @@ | |
}, | ||
add: { | ||
method: 'PUT' | ||
}, | ||
update: { | ||
url: './api/list/:itemId', | ||
method: 'PATCH', | ||
} | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<form class="form-horizontal" name="fieldsForm" ng-submit="$vm.saveField()" novalidate> | ||
<div class="modal-header bg-primary"> | ||
<h3 class="modal-title">{{$vm.customField.id ? 'Update' : 'Add'}} custom field</h3> | ||
</div> | ||
<div class="modal-body"> | ||
|
||
<div class="form-group" ng-class="{ 'has-error' : fieldsForm.name.$invalid && !fieldsForm.name.$pristine }"> | ||
<label class="col-sm-2 control-label"> | ||
Name | ||
<i class="fa fa-asterisk text-danger"></i> | ||
</label> | ||
<div class="col-sm-10"> | ||
<input class="form-control" name="name" ng-model="$vm.customField.name" placeholder="Ex: cvss, threatActor, businessRisk" required type="text"> | ||
<p class="help-block" ng-show="fieldsForm.name.$invalid && !fieldsForm.name.$pristine">This field is required.</p> | ||
</div> | ||
</div> | ||
<div class="form-group" ng-class="{ 'has-error' : fieldsForm.label.$invalid && !fieldsForm.label.$pristine }"> | ||
<label class="col-sm-2 control-label"> | ||
Label | ||
<i class="fa fa-asterisk text-danger"></i> | ||
</label> | ||
<div class="col-sm-10"> | ||
<input class="form-control" name="label" ng-model="$vm.customField.label" placeholder="Ex: CVSS, Threat actor, Business risk" required type="text"> | ||
<p class="help-block" ng-show="fieldsForm.label.$invalid && !fieldsForm.label.$pristine">This field is required.</p> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group" ng-class="{ 'has-error' : fieldsForm.description.$invalid && !fieldsForm.description.$pristine }"> | ||
<label class="col-sm-2 control-label"> | ||
Description | ||
<i class="fa fa-asterisk text-danger"></i> | ||
</label> | ||
<div class="col-sm-10"> | ||
<input class="form-control" name="description" ng-model="$vm.customField.description" placeholder="A brief description of the custom field" required type="text"> | ||
<p class="help-block" ng-show="fieldsForm.description.$invalid && !fieldsForm.description.$pristine">This field is required.</p> | ||
</div> | ||
</div> | ||
<div class="form-group" ng-class="{ 'has-error' : fieldsForm.type.$invalid && !fieldsForm.type.$pristine }"> | ||
<label class="col-sm-2 control-label"> | ||
Type | ||
<i class="fa fa-asterisk text-danger"></i> | ||
</label> | ||
<div class="col-sm-10"> | ||
<select class="form-control" name="type" ng-model="$vm.customField.type" | ||
ng-options="fieldType for fieldType in $vm.reference.types" | ||
placeholder="Field's type" required></select> | ||
<p class="help-block" ng-show="fieldsForm.type.$invalid && !fieldsForm.type.$pristine">This field is required.</p> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label class="col-sm-2 control-label"> | ||
Possible values | ||
</label> | ||
<div class="col-sm-10"> | ||
<textarea class="form-control" name="options" ng-model="$vm.customField.options" rows="5" placeholder="Possible values, one per line" type="text"></textarea> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="modal-footer text-left"> | ||
<button class="btn btn-default" ng-click="$vm.cancel()" type="button">Cancel</button> | ||
<button class="btn btn-primary pull-right" ng-disabled="fieldsForm.$invalid" type="submit">Save field</button> | ||
</div> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters