Epic-231:versioning, and backup the configuration
[sdnc/oam.git] / configbackuprestore / vnfconfigbackupservice / src / main / webapp / node_modules / angular-object-diff / README.md
1 # angular-diff
2 An Angular JS plugin to compare and show object differences in JSON format. [Demo](http://hipster-labs.github.io/angular-object-diff/)
3
4 ![Screenshot](/screenshot.png)
5 # Installation
6
7 with bower
8 ```
9 bower install angular-object-diff --save
10 ```
11
12 ```
13 <link type="text/css" href="bower_components/dist/angular-object-diff.css" rel='stylesheet'>
14 <script type="text/javascript" src="bower_components/dist/angular-object-diff.js"></script>
15 ```
16
17 or with npm
18 ```
19 npm i angular-object-diff
20 ```
21
22 # Available methods on `ObjectDiff` service
23
24
25 `setOpenChar`: set the opening character for the view, default is `{`
26
27 `setCloseChar`: set the closing character for the view, default is `}`
28
29 `diff`: compare and build all the difference of two objects including prototype properties
30
31 `diffOwnProperties`: compare and build the difference of two objects taking only its own properties into account
32
33 `toJsonView`: format a diff object to a full JSON formatted object view
34
35 `toJsonDiffView`: format a diff object to a JSON formatted view with only changes
36
37 `objToJsonView`: format any javascript object to a JSON formatted view
38
39
40 # Available filters
41
42 `toJsonView`: format a diff object to a full JSON formatted object view
43
44 `toJsonDiffView`: format a diff object to a JSON formatted view with only changes
45
46 `objToJsonView`: format any javascript object to a JSON formatted view
47
48
49 # Usage
50
51 Declare the dependency
52 ```
53 angular.module('myModule', ['ds.objectDiff']);
54
55 ```
56
57 Inject the service
58
59 ```javascript
60 angular.module('myModule')
61     .controller('MyController', ['$scope', 'ObjectDiff', function($scope, ObjectDiff){
62         $scope.yourObjectOne = {//all your object attributes and values here};
63         $scope.yourObjectTwo = {//all your object attributes and values here};
64
65         // This is required only if you want to show a JSON formatted view of your object without using a filter
66         $scope.yourObjectOneJsonView = ObjectDiff.objToJsonView($scope.yourObjectOne);
67         $scope.yourObjectTwoJsonView = ObjectDiff.objToJsonView($scope.yourObjectTwo);
68
69         // you can directly diff your objects js now or parse a Json to object and diff
70         var diff = ObjectDiff.diffOwnProperties($scope.yourObjectOne, $scope.yourObjectTwo);
71         
72         // you can directly diff your objects including prototype properties and inherited properties using `diff` method
73         var diffAll = ObjectDiff.diff($scope.yourObjectOne, $scope.yourObjectTwo);
74
75         // gives a full object view with Diff highlighted
76         $scope.diffValue = ObjectDiff.toJsonView(diff);
77         
78         // gives object view with onlys Diff highlighted
79         $scope.diffValueChanges = ObjectDiff.toJsonDiffView(diff);
80     
81     }]);
82 ```
83
84 Bind the variables directly in your html using the `ng-bind-html` angular directive.
85 Use a `<pre>` element for better results
86
87 ```html
88 <pre ng-bind-html="diffValue"></pre>
89 <pre ng-bind-html="diffValueChanges"></pre>
90 <pre ng-bind-html="yourObjectOneJsonView"></pre>
91 <pre ng-bind-html="yourObjectTwoJsonView"></pre>
92 ```
93
94 The same can be done with filters as well
95
96 ```javascript
97 angular.module('myModule')
98     .controller('MyController', ['$scope', 'ObjectDiff', function($scope, ObjectDiff){
99         $scope.yourObjectOne = {//all your object attributes and values here};
100         $scope.yourObjectTwo = {//all your object attributes and values here};
101
102         // you can directly diff your objects js now or parse a Json to object and diff
103         var diff = ObjectDiff.diffOwnProperties($scope.yourObjectOne, $scope.yourObjectTwo);
104         
105         // you can directly diff your objects including prototype properties and inherited properties using `diff` method
106         var diffAll = ObjectDiff.diff($scope.yourObjectOne, $scope.yourObjectTwo);
107     
108     }]);
109 ```
110
111 Bind the variables directly in your html using the `ng-bind-html` angular directive.
112 Use a `<pre>` element for better results
113
114 ```html
115 <pre ng-bind-html="diffValue | toJsonView"></pre>
116 <pre ng-bind-html="diffValueChanges | toJsonDiffView"></pre>
117 <pre ng-bind-html="yourObjectOneJsonView | objToJsonView"></pre>
118 <pre ng-bind-html="yourObjectTwoJsonView | objToJsonView"></pre>
119 ```
120
121 Inspired from https://github.com/NV/objectDiff.js