diff --git a/README.md b/README.md
index 628ac05..1d6c645 100644
--- a/README.md
+++ b/README.md
@@ -11,7 +11,7 @@ When you run your application in browser with „ionic serve” the Logger uses
## Dependencies
-- [ngCordova](http://ngcordova.com/)
+- [ngCordova](http://ngcordova.com/) ( required version v0.1.14-alpha )
- [org.apache.cordova.file](https://github.com/apache/cordova-plugin-file)
## Installation
@@ -30,6 +30,9 @@ Include *filelogger.min.js* and ng-cordova.js or *ng-cordova.min.js* in your ind
```
+Comment: you don't have to use the complete ngCordova package. I suggest to create a [Custom Build](http://ngcordova.com/build/) with file module.
+
+
## Usage
### $fileLogger.log()
@@ -72,9 +75,8 @@ You can delete the logfile from the filestore. This method returns a promise.
### Example use
```js
-var app = angular.module('starter', ['ionic', 'fileLogger']);
-
-app.controller('mainCtrl', ['$scope', '$fileLogger', function($scope, $fileLogger) {
+angular.module('starter', ['ionic', 'fileLogger'])
+ .controller('mainCtrl', ['$scope', '$fileLogger', function($scope, $fileLogger) {
function testing() {
diff --git a/bower.json b/bower.json
index 8751ab8..d6a109b 100644
--- a/bower.json
+++ b/bower.json
@@ -1,6 +1,6 @@
{
"name": "filelogger",
- "version": "1.0.4",
+ "version": "1.1.0",
"homepage": "https://github.com/pbakondy/filelogger",
"authors": [
"Peter Bakondy "
@@ -14,7 +14,7 @@
"config"
],
"dependencies": {
- "ngCordova": ">= 0.1.8-alpha"
+ "ngCordova": ">= 0.1.14-alpha"
},
"keywords": [
"cordova",
diff --git a/dist/filelogger.js b/dist/filelogger.js
index dfc711d..a682f9d 100644
--- a/dist/filelogger.js
+++ b/dist/filelogger.js
@@ -4,11 +4,11 @@
* See LICENSE in this repository for license information
*/
(function(){
-/* global angular, console */
+/* global angular, console, cordova */
// install : cordova plugin add org.apache.cordova.file
-angular.module('fileLogger', ['ngCordova'])
+angular.module('fileLogger', ['ngCordova.plugins.file'])
.factory('$fileLogger', ['$q', '$window', '$cordovaFile', '$timeout', function ($q, $window, $cordovaFile, $timeout) {
'use strict';
@@ -136,7 +136,7 @@ angular.module('fileLogger', ['ngCordova'])
function writeLog(message) {
var q = $q.defer();
- if (!$window.cordova) {
+ if (isBrowser()) {
// running in browser with 'ionic serve'
if (!$window.localStorage[storageFilename]) {
@@ -148,12 +148,28 @@ angular.module('fileLogger', ['ngCordova'])
} else {
- $cordovaFile.writeFile(storageFilename, message, { append: true }).then(
+ $cordovaFile.checkFile(cordova.file.dataDirectory, storageFilename).then(
function() {
- q.resolve();
+ // writeExistingFile(path, fileName, text)
+ $cordovaFile.writeExistingFile(cordova.file.dataDirectory, storageFilename, message).then(
+ function() {
+ q.resolve();
+ },
+ function(error) {
+ q.reject(error);
+ }
+ );
},
- function(error) {
- q.reject(error);
+ function() {
+ // writeFile(path, fileName, text, replaceBool)
+ $cordovaFile.writeFile(cordova.file.dataDirectory, storageFilename, message, true).then(
+ function() {
+ q.resolve();
+ },
+ function(error) {
+ q.reject(error);
+ }
+ );
}
);
@@ -166,10 +182,10 @@ angular.module('fileLogger', ['ngCordova'])
function getLogfile() {
var q = $q.defer();
- if (!$window.cordova) {
+ if (isBrowser()) {
q.resolve($window.localStorage[storageFilename]);
} else {
- $cordovaFile.readAsText(storageFilename).then(
+ $cordovaFile.readAsText(cordova.file.dataDirectory, storageFilename).then(
function(result) {
q.resolve(result);
},
@@ -186,11 +202,11 @@ angular.module('fileLogger', ['ngCordova'])
function deleteLogfile() {
var q = $q.defer();
- if (!$window.cordova) {
+ if (isBrowser()) {
$window.localStorage.removeItem(storageFilename);
q.resolve();
} else {
- $cordovaFile.removeFile(storageFilename).then(
+ $cordovaFile.removeFile(cordova.file.dataDirectory, storageFilename).then(
function(result) {
q.resolve(result);
},
diff --git a/dist/filelogger.min.js b/dist/filelogger.min.js
index c40eebc..b528fb5 100644
--- a/dist/filelogger.min.js
+++ b/dist/filelogger.min.js
@@ -3,4 +3,4 @@
* Copyright 2015 Peter Bakondy https://github.com/pbakondy
* See LICENSE in this repository for license information
*/
-!function(){angular.module("fileLogger",["ngCordova"]).factory("$fileLogger",["$q","$window","$cordovaFile","$timeout",function(o,e,n,r){"use strict";function l(){return!e.cordova&&!e.PhoneGap&&!e.phonegap}function a(o){angular.isString(o)?(o=o.toUpperCase(),-1===h.indexOf(o)&&(o="INFO")):o="INFO";for(var e=(new Date).toJSON(),n=Array.prototype.slice.call(arguments,1),r=[e,o],a=0;a0?(m=o,!0):!1}function g(){var o=Array.prototype.slice.call(arguments,0);o.unshift("DEBUG"),a.apply(void 0,o)}function p(){var o=Array.prototype.slice.call(arguments,0);o.unshift("INFO"),a.apply(void 0,o)}function f(){var o=Array.prototype.slice.call(arguments,0);o.unshift("WARN"),a.apply(void 0,o)}function v(){var o=Array.prototype.slice.call(arguments,0);o.unshift("ERROR"),a.apply(void 0,o)}var d=[],y=!1,h=["DEBUG","INFO","WARN","ERROR"],m="messages.log";return{log:a,getLogfile:i,deleteLogfile:s,setStorageFilename:u,debug:g,info:p,warn:f,error:v}}])}();
\ No newline at end of file
+!function(){angular.module("fileLogger",["ngCordova.plugins.file"]).factory("$fileLogger",["$q","$window","$cordovaFile","$timeout",function(e,o,n,r){"use strict";function l(){return!o.cordova&&!o.PhoneGap&&!o.phonegap}function t(e){angular.isString(e)?(e=e.toUpperCase(),-1===h.indexOf(e)&&(e="INFO")):e="INFO";for(var o=(new Date).toJSON(),n=Array.prototype.slice.call(arguments,1),r=[o,e],t=0;t0?(m=e,!0):!1}function g(){var e=Array.prototype.slice.call(arguments,0);e.unshift("DEBUG"),t.apply(void 0,e)}function f(){var e=Array.prototype.slice.call(arguments,0);e.unshift("INFO"),t.apply(void 0,e)}function p(){var e=Array.prototype.slice.call(arguments,0);e.unshift("WARN"),t.apply(void 0,e)}function d(){var e=Array.prototype.slice.call(arguments,0);e.unshift("ERROR"),t.apply(void 0,e)}var v=[],y=!1,h=["DEBUG","INFO","WARN","ERROR"],m="messages.log";return{log:t,getLogfile:c,deleteLogfile:s,setStorageFilename:u,debug:g,info:f,warn:p,error:d}}])}();
\ No newline at end of file
diff --git a/package.json b/package.json
index 6d89864..0f1619a 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "filelogger",
"private": false,
"main": "dist/filelogger",
- "version": "1.0.4",
+ "version": "1.1.0",
"repository": {
"url": "git://github.com/pbakondy/filelogger.git"
},
diff --git a/src/filelogger.js b/src/filelogger.js
index 6b8561f..26946fa 100644
--- a/src/filelogger.js
+++ b/src/filelogger.js
@@ -1,8 +1,8 @@
-/* global angular, console */
+/* global angular, console, cordova */
// install : cordova plugin add org.apache.cordova.file
-angular.module('fileLogger', ['ngCordova'])
+angular.module('fileLogger', ['ngCordova.plugins.file'])
.factory('$fileLogger', ['$q', '$window', '$cordovaFile', '$timeout', function ($q, $window, $cordovaFile, $timeout) {
'use strict';
@@ -130,7 +130,7 @@ angular.module('fileLogger', ['ngCordova'])
function writeLog(message) {
var q = $q.defer();
- if (!$window.cordova) {
+ if (isBrowser()) {
// running in browser with 'ionic serve'
if (!$window.localStorage[storageFilename]) {
@@ -142,12 +142,28 @@ angular.module('fileLogger', ['ngCordova'])
} else {
- $cordovaFile.writeFile(storageFilename, message, { append: true }).then(
+ $cordovaFile.checkFile(cordova.file.dataDirectory, storageFilename).then(
function() {
- q.resolve();
+ // writeExistingFile(path, fileName, text)
+ $cordovaFile.writeExistingFile(cordova.file.dataDirectory, storageFilename, message).then(
+ function() {
+ q.resolve();
+ },
+ function(error) {
+ q.reject(error);
+ }
+ );
},
- function(error) {
- q.reject(error);
+ function() {
+ // writeFile(path, fileName, text, replaceBool)
+ $cordovaFile.writeFile(cordova.file.dataDirectory, storageFilename, message, true).then(
+ function() {
+ q.resolve();
+ },
+ function(error) {
+ q.reject(error);
+ }
+ );
}
);
@@ -160,10 +176,10 @@ angular.module('fileLogger', ['ngCordova'])
function getLogfile() {
var q = $q.defer();
- if (!$window.cordova) {
+ if (isBrowser()) {
q.resolve($window.localStorage[storageFilename]);
} else {
- $cordovaFile.readAsText(storageFilename).then(
+ $cordovaFile.readAsText(cordova.file.dataDirectory, storageFilename).then(
function(result) {
q.resolve(result);
},
@@ -180,11 +196,11 @@ angular.module('fileLogger', ['ngCordova'])
function deleteLogfile() {
var q = $q.defer();
- if (!$window.cordova) {
+ if (isBrowser()) {
$window.localStorage.removeItem(storageFilename);
q.resolve();
} else {
- $cordovaFile.removeFile(storageFilename).then(
+ $cordovaFile.removeFile(cordova.file.dataDirectory, storageFilename).then(
function(result) {
q.resolve(result);
},