Skip to content

Commit 6c83fd8

Browse files
committed
add tests and mocks
1 parent 1c7bbb8 commit 6c83fd8

File tree

17 files changed

+403
-289
lines changed

17 files changed

+403
-289
lines changed

.jshintrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"undef": true,
3+
"unused": true,
4+
"globals": {
5+
"angular": true,
6+
"Promise": true,
7+
"module": true,
8+
"inject": true,
9+
"themeManager": true
10+
},
11+
"devel": true,
12+
"jasmine" : true
13+
}

app/app.js

Lines changed: 1 addition & 234 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
(function(global) {
22
themeManager.init();
33

4-
var SELECTION_SIZE_FOR_POINT = 4;
5-
64
angular.module('app', ['ngLodash', 'xml'])
75
.config(function (lodash, x2jsProvider) {
86
x2jsProvider.config = {
@@ -20,236 +18,5 @@
2018
attributePrefix: '_',
2119
arrayAccessFormPaths: ['xmpmeta.RDF.Description.RecommendedFrames.Bag.li']
2220
};
23-
})
24-
.controller('MainController', ['$scope', 'csInterface', 'rmdBridge',
25-
'rmdDefault', 'lodash', 'psEvent', 'rmdFrameStruct',
26-
function ($scope, csInterface, RMD, rmdDefault, _, psEvent, rmdFrameStruct) {
27-
28-
var activeArea = null;
29-
var gExtensionID = csInterface.getExtensionID();
30-
var listenTo = [psEvent.set, psEvent.select];
31-
32-
// Tell Photoshop to not unload us when closed
33-
function Persistent(inOn) {
34-
gStartDate = new Date();
35-
var event;
36-
if (inOn) {
37-
event = new CSEvent("com.adobe.PhotoshopPersistent", "APPLICATION");
38-
} else {
39-
event = new CSEvent("com.adobe.PhotoshopUnPersistent", "APPLICATION");
40-
}
41-
event.extensionId = gExtensionID;
42-
csInterface.dispatchEvent(event);
43-
SetResultTime();
44-
}
45-
// Tell Photoshop the events we want to listen for
46-
var _register = function(inOn, inEvents) {
47-
var event;
48-
if (inOn) {
49-
event = new CSEvent("com.adobe.PhotoshopRegisterEvent", "APPLICATION");
50-
} else {
51-
event = new CSEvent("com.adobe.PhotoshopUnRegisterEvent", "APPLICATION");
52-
}
53-
event.extensionId = gExtensionID;
54-
event.data = inEvents;
55-
csInterface.dispatchEvent(event);
56-
};
57-
58-
/**
59-
* Toggle the 'set' event (Area mark) listener.
60-
* @param status - True or false -> on or off.
61-
*/
62-
var selectListener = function(status) {
63-
_register(status, listenTo.toString());
64-
};
65-
// deactivate leftover listeners on startup
66-
selectListener(false);
67-
68-
$scope.rmd = RMD.xmp.xmpmeta.RDF.Description;
69-
$scope.documentSize = {};
70-
RMD.getTargetName(function(name){$scope.targetName = name;});
71-
72-
73-
74-
// TODO: Remove debugging exposures.
75-
global._scope = $scope;
76-
global.RMD = RMD;
77-
78-
// store the original image size
79-
csInterface.evalScript('getDocumentSize()', function(value) {
80-
$scope.documentSize = JSON.parse(value);
81-
});
82-
83-
/**
84-
* Event callback for Photoshop Events. Currently only the 'set' event.
85-
* @param csEvent Photoshop Event.
86-
*/
87-
var PhotoshopCallbackUnique = function(csEvent) {
88-
// console.log('receiving Callback: ', csEvent);
89-
if (typeof csEvent.data === "string") {
90-
var eventData = csEvent.data.replace("ver1,{", "{");
91-
var data = JSON.parse(eventData);
92-
if(data.eventData.null._property === 'selection' && data.eventID === psEvent.set
93-
&& data.eventData.to._obj === 'rectangle' && activeArea){
94-
if(data.eventData.to.top._unit === 'pixelsUnit'){
95-
setAreaValues(data.eventData.to);
96-
} else {
97-
alert('Please set the units to Pixels. Other units are currently not supported.');
98-
}
99-
}
100-
} else {
101-
console.error("PhotoshopCallbackUnique expecting string for csEvent.data!");
102-
}
103-
};
104-
105-
/**
106-
* Get the RMD object node for the given area key.
107-
* @returns {*} RMD node.
108-
*/
109-
var getNodeForActiveArea = function() {
110-
if(activeArea === 'default') {
111-
return $scope.rmd.CropArea;
112-
} else if (activeArea === 'safe') {
113-
return $scope.rmd.SafeArea;
114-
} else if (activeArea === 'pivot') {
115-
return $scope.rmd.PivotPoint;
116-
} else {
117-
return $scope.rmd.RecommendedFrames.Bag.li[activeArea]
118-
}
119-
};
120-
121-
/**
122-
* Sets the values returned by a Photoshop event in the RMD node.
123-
* @param ps_data Photoshop event property.
124-
*/
125-
var setAreaValues = function(ps_data) {
126-
var node, x, y, width, height;
127-
node = getNodeForActiveArea();
128-
// PS returns the are as left, top, width height.
129-
// The RMD standard requires centerX, centerY, width height.
130-
width = ps_data.right._value - ps_data.left._value;
131-
height = ps_data.bottom._value - ps_data.top._value;
132-
x = ps_data.left._value + width/2;
133-
y = ps_data.top._value + height/2;
134-
node.x.__text = (x / $scope.documentSize.width).toString();
135-
node.y.__text = (y / $scope.documentSize.height).toString();
136-
if(node.w && node.h) {
137-
node.w.__text = (width / $scope.documentSize.width).toString();
138-
node.h.__text = (height / $scope.documentSize.height).toString();
139-
}
140-
141-
$scope.$apply();
142-
};
143-
144-
var setSelectionFromRmd = function() {
145-
var x, y, width, height, left, top, coords;
146-
var node = getNodeForActiveArea();
147-
x = parseFloat(node.x.__text) * $scope.documentSize.width;
148-
y = parseFloat(node.y.__text) * $scope.documentSize.height;
149-
if(node.w && node.h) {
150-
width = parseFloat(node.w.__text) * $scope.documentSize.width;
151-
height = parseFloat(node.h.__text) * $scope.documentSize.height;
152-
} else {
153-
width = SELECTION_SIZE_FOR_POINT;
154-
height = SELECTION_SIZE_FOR_POINT;
155-
}
156-
left = parseInt(x - width/2);
157-
top = parseInt(y - height/2);
158-
coords = {
159-
left: left,
160-
top: top,
161-
right: parseInt(left + width),
162-
bottom: parseInt(top + height)
163-
};
164-
csInterface.evalScript('makeSelection(' + JSON.stringify(coords) + ')');
165-
};
166-
167-
// all callbacks need to be unique so only your panel gets them
168-
// for Photoshop specific add on the id of your extension
169-
csInterface.addEventListener("com.adobe.PhotoshopJSONCallback" + gExtensionID, PhotoshopCallbackUnique);
170-
171-
/**
172-
* Adds a new crop region to the metadata. There are three types: The default crop area,
173-
* the safety area and a list of recommended crop areas
174-
* @param name - the name of the area. One of 'default', 'safe' or a number.
175-
*/
176-
$scope.addCropArea = function(name) {
177-
var struct;
178-
if(name === undefined) {
179-
$scope.rmd.RecommendedFrames.Bag.li.push(_.cloneDeep(rmdFrameStruct));
180-
} else {
181-
struct = _.cloneDeep(rmdFrameStruct);
182-
delete struct.MinAspectRatio;
183-
delete struct.MaxAspectRatio;
184-
if(name === 'default') {
185-
delete struct.MaxWidth;
186-
$scope.rmd.CropArea = struct;
187-
} else if(name === 'safe') {
188-
delete struct.MinWidth;
189-
$scope.rmd.SafeArea = struct;
190-
}
191-
}
192-
};
193-
/**
194-
* Removes the crop area from the metadata.
195-
* @param index - the name of the area to remove. One of 'default', 'safe' or a number.
196-
*/
197-
$scope.removeCropArea = function(index) {
198-
// deactivate area
199-
if(activeArea === index) {
200-
$scope.setActiveArea(null);
201-
}
202-
if(index === 'default') {
203-
delete $scope.rmd.CropArea;
204-
} else if(index === 'safe') {
205-
delete $scope.rmd.SafeArea;
206-
} else {
207-
$scope.rmd.RecommendedFrames.Bag.li.splice(index, 1);
208-
}
209-
};
210-
/**
211-
* Check if the given area is active (listening to events)
212-
* @param area - the name of the area.
213-
* @returns {boolean}
214-
*/
215-
$scope.isAreaActive = function(area) {
216-
return area === activeArea;
217-
};
218-
/**
219-
* Sets the given area as active.
220-
* @param area - the name of the area.
221-
*/
222-
$scope.setActiveArea = function(area) {
223-
csInterface.evalScript('clearSelection()');
224-
if(activeArea === area || area === null) {
225-
// turn it off
226-
selectListener(false);
227-
activeArea = null;
228-
} else {
229-
if(!activeArea) {
230-
selectListener(true);
231-
}
232-
activeArea = area;
233-
setSelectionFromRmd();
234-
}
235-
};
236-
237-
$scope.commit = function(){
238-
RMD.storeXMP().then(function(response) {
239-
if(response == 0) {
240-
alert('XMP updated');
241-
}
242-
});
243-
};
244-
245-
$scope.revert = function() {
246-
RMD.extractXMP()
247-
.then(function(xmp) {
248-
$scope.rmd = xmp.xmpmeta.RDF.Description;
249-
$scope.$apply();
250-
});
251-
};
252-
253-
}
254-
]);
21+
});
25522
}(window));

app/constants.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ angular.module('app')
1818
"xmpmeta": {
1919
"RDF": {
2020
"Description": {
21-
"MinWidth": {
22-
"__prefix": "rmd",
23-
"__text": "360"
24-
},
2521
"Interpolation": {
2622
"__prefix": "rmd",
2723
"__text": "linear"

0 commit comments

Comments
 (0)