Skip to content
Browse files

support creating edit starting from an edit

also fix the log notifications after creating edits
  • Loading branch information...
1 parent 8adf3ae commit 4b1ad656c8314bebde75d485663658d42c7a378e @Dieterbe committed Dec 27, 2013
Showing with 34 additions and 18 deletions.
  1. +14 −3 js/controllers.js
  2. +1 −1 js/services.js
  3. +19 −14 pixie.go
View
17 js/controllers.js
@@ -83,9 +83,20 @@ photosControllers.controller('PhotosCtrl', ['$scope', '$routeParams', 'Binds', '
};
$scope.newEdit = function () {
$scope.$apply(function () {
- console.log('creating edit for :', $scope.photosAll[$scope.focusIndex] );
- $scope.photosAll[$scope.focusIndex] = Edit.new($scope.photosAll[$scope.focusIndex], function(response) {
- $scope.logs.push({msg: "created new edit for " + $scope.photosAll[$scope.focusIndex].name, type: 'info'});
+ var img = $scope.photosAll[$scope.focusIndex];
+ var edits_pre = Object.keys(img['edits']).length;
+ if ($scope.subFocusIndex > 0 ) {
+ var cur = $scope.getCurrentPhoto();
+ img['start_from'] = cur['dir'] + "/" + cur['name'];
+ } else {
+ img['start_from'] = "";
+ }
+ $scope.photosAll[$scope.focusIndex] = Edit.new(img, function(response) {
+ var edits_post = Object.keys($scope.photosAll[$scope.focusIndex]['edits']).length;
+ $scope.logs.push({
+ msg: "created " + (edits_post - edits_pre) + " new edits for " + $scope.photosAll[$scope.focusIndex].name,
+ type: 'info'
+ });
}, function(response) {
$scope.logs.push({msg: "failed to edit " + $scope.photosAll[$scope.focusIndex].name + ": " + response.data.msg, type: 'error'});
});
View
2 js/services.js
@@ -27,7 +27,7 @@ photosServices.factory('Photo', ['$resource',
photosServices.factory('Edit', ['$resource',
function($resource){
return $resource('/api/edit', {}, {
- new: { method:'POST', params:{id: "@id", dir:"@dir", name:"@name"}, isArray: false},
+ new: { method:'POST', params:{id: "@id", dir:"@dir", name:"@name", start_from: "@start_from"}, isArray: false},
});
}
]);
View
33 pixie.go
@@ -47,7 +47,6 @@ func Expand(in string) (out string) {
usr, _ := user.Current()
home_dir := usr.HomeDir
out := strings.Replace(in, "~/", home_dir+"/", 1)
- fmt.Println(out)
return out
}
return in
@@ -240,6 +239,7 @@ func api_edit_handler(w http.ResponseWriter, r *http.Request, conn_sqlite *sql.D
}
dir := r.Form.Get("dir")
name := r.Form.Get("name")
+ start_from := r.Form.Get("start_from")
if dir == "" || name == "" {
backend.ErrorJson(w, backend.Resp{fmt.Sprintf("Invalid request: %s", err)}, 503)
return
@@ -253,12 +253,20 @@ func api_edit_handler(w http.ResponseWriter, r *http.Request, conn_sqlite *sql.D
backend.ErrorJson(w, backend.Resp{fmt.Sprintf("dir is not in a format that supports an edits dir")}, 409)
return
}
- orig := path.Join(dir, name)
- ext := path.Ext(name)
- tmp := path.Join(edits_dir, name[:len(name)-len(ext)]+"-save-your-edit-to-a-new-file"+ext)
- err = cp.Cp(tmp, orig)
+
+ var start_from_name string
+ if start_from != "" {
+ start_from_name = path.Base(start_from)
+ } else {
+ start_from = path.Join(dir, name)
+ start_from_name = name
+ }
+ start_from_ext := path.Ext(start_from_name)
+ tmp := path.Join(edits_dir, start_from_name[:len(start_from_name)-len(start_from_ext)]+"-save-your-edit-to-a-new-file"+start_from_ext)
+
+ err = cp.Cp(tmp, start_from)
if err != nil {
- backend.ErrorJson(w, backend.Resp{fmt.Sprintf("Could not copy %s to %s because: %s", orig, tmp, err)}, 503)
+ backend.ErrorJson(w, backend.Resp{fmt.Sprintf("Could not copy %s to %s because: %s", start_from, tmp, err)}, 503)
return
}
// this doesn't actually help with preventing write. but I guess that doesn't really matter anyway.
@@ -284,16 +292,13 @@ func api_edit_handler(w http.ResponseWriter, r *http.Request, conn_sqlite *sql.D
backend.ErrorJson(w, backend.Resp{fmt.Sprintf("Cannot get file tags: '%s': %s", dir, err)}, 503)
return
}
- edits_filetags := make(map[string]string)
- if edits_dir != "" {
- edits_filetags, err = backend.GetFileTags(edits_dir, conn_sqlite)
- if err != nil {
- backend.ErrorJson(w, backend.Resp{fmt.Sprintf("Cannot get file tags: '%s': %s", edits_dir, err)}, 503)
- return
- }
+ edits_filetags, err := backend.GetFileTags(edits_dir, conn_sqlite)
+ if err != nil {
+ backend.ErrorJson(w, backend.Resp{fmt.Sprintf("Cannot get file tags: '%s': %s", edits_dir, err)}, 503)
+ return
}
- p, err := NewPhoto(id, dir, name, ext, filetags, edits_dir, edits_filetags)
+ p, err := NewPhoto(id, dir, name, path.Ext(name), filetags, edits_dir, edits_filetags)
if err != nil {
fmt.Printf("WARNING: failed to create Photo instance: %s\n", err)
}

0 comments on commit 4b1ad65

Please sign in to comment.
Something went wrong with that request. Please try again.