Skip to content

Commit

Permalink
following ngCordova changes
Browse files Browse the repository at this point in the history
ngCordova.plugins.file changes: modified methods, parameters
  • Loading branch information
pbakondy committed Mar 24, 2015
1 parent 6a264af commit 4b5f765
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 30 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,6 +30,9 @@ Include *filelogger.min.js* and ng-cordova.js or *ng-cordova.min.js* in your ind
<script src="cordova.js"></script>
```

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()
Expand Down Expand Up @@ -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() {

Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "filelogger",
"version": "1.0.4",
"version": "1.1.0",
"homepage": "https://github.com/pbakondy/filelogger",
"authors": [
"Peter Bakondy <[email protected]>"
Expand All @@ -14,7 +14,7 @@
"config"
],
"dependencies": {
"ngCordova": ">= 0.1.8-alpha"
"ngCordova": ">= 0.1.14-alpha"
},
"keywords": [
"cordova",
Expand Down
38 changes: 27 additions & 11 deletions dist/filelogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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]) {
Expand All @@ -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);
}
);
}
);

Expand All @@ -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);
},
Expand All @@ -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);
},
Expand Down
2 changes: 1 addition & 1 deletion dist/filelogger.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
38 changes: 27 additions & 11 deletions src/filelogger.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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]) {
Expand All @@ -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);
}
);
}
);

Expand All @@ -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);
},
Expand All @@ -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);
},
Expand Down

0 comments on commit 4b5f765

Please sign in to comment.