Skip to content

Commit

Permalink
Merge pull request #35 from percolate/feature/v5_manual_entry
Browse files Browse the repository at this point in the history
Feature/v5 manual entry
  • Loading branch information
devsoft-cz authored Jul 18, 2018
2 parents 0a1ff43 + 8e03863 commit a95f921
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 26 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ You should see that:

## Changelog

### 4.x-1.3.0

* Manual settings UI

### 4.x-1.2.7

* Adding support for Percolate's overhauled v5 Taxonomy API
Expand Down
73 changes: 73 additions & 0 deletions frontend/scripts/api/percolate.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,35 @@ angular.module('wpPercolate', [])
/* ------------------------------------
* Setup screen
* ------------------------------------ */

getLicenseV5: function(data) {
return callApi('v5/license/license:' + data.license, data);
},
getPlatformV5: function(data) {
return callApi('v5/platform/' + data.platform, data);
},
getChannelV5: function(data) {
return callApi('v5/channel/' + data.channel, data);
},
getUserV5: function(data) {
return callApi('v5/me', data)
.then(d => {
if (!d || !d.data || !d.data.data)
return {
data: null
};
return {
data: {
username: d.data.data.email,
email: d.data.data.email,
name: d.data.data.name,
id: d.data.data.id.replace('user:',''),
active: true,
}
};
});
},

getUser: function (data) {
return callApi('v3/me', data)
},
Expand Down Expand Up @@ -63,6 +92,50 @@ angular.module('wpPercolate', [])
return callApi('v3/licenses/' + data.license + '/users', data)
},

getUsersByLicenseV5: function (data){
var orig = data;
console.log(orig);
return callApi('v5/user_role/', {
key: data.key,
fields: {
scope_ids: "license:" + data.license
}
}).then(function(data) {
console.log(data);
var userIds = data.data.data.map(function(v) {
return v.user_id;
});
console.log('Loaded user IDs: ',userIds);
return callApi('v5/user/', {
key: orig.key,
fields: angular.extend({
ids: userIds.join(','),
limit: orig.fields.limit,
offset: orig.fields.offset
}, orig.fields)
})
.then(function(users) {
users = users.data;
return {
data: {
pagination: {
total: users.meta.total,
limit: users.meta.query.limit,
offset: users.meta.query.offset
},
data: users.data.map(function(u) {
u.id = parseInt(u.id.replace('user:',''));
return {
user: u,
id: u.id
};
})
}
};
});
})
},

/* ------------------------------------
* Templates screen
* ------------------------------------ */
Expand Down
80 changes: 75 additions & 5 deletions frontend/scripts/settings/controllers/add.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,81 @@ angular.module('myApp')
if( form.$invalid ) {
return
}

// extend new channel object
angular.extend($scope.activeChannel, $scope.formData)
console.log('Submiting form, current dataset: ', $scope.activeChannel)
$state.go('add.topics')
var fd = angular.extend({}, $scope.formData);
fd.license = fd.license.trim().replace('license:','');
fd.platform = fd.platform.trim();
fd.channel = fd.channel.trim();

if (fd.platform.indexOf('platform:') != 0)
fd.platform = 'platform:' + fd.platform;
if (fd.channel.indexOf('channel:') != 0)
fd.channel = 'channel:' + fd.channel;

$scope.showLoader('Please wait while we verify the configuration...')
Percolate.getUserV5({key: fd.key})
.then(d => {
if (!d.data || !d.data) {
$scope.stopLoader()
$scope.showError("Invalid API Key");
return;
}
fd.user = d.data;

console.log("API Key validated",d);
return Percolate.getLicenseV5({key: fd.key, license: fd.license})
},err => {
$scope.stopLoader()
$scope.showError("Invalid API Key");
})
.then(d => {
if (!d) return;
if (!d.data || !d.data.data) {
$scope.stopLoader()
$scope.showError("Invalid License ID");
return;
}

console.log("License validated",d);
return Percolate.getPlatformV5({key: fd.key, platform: fd.platform})
},err => {
$scope.stopLoader()
$scope.showError("Invalid License ID");
})
.then(d => {
if (!d) return;
if (!d.data || !d.data.data) {
$scope.stopLoader()
$scope.showError("Invalid Platform ID");
return;
}

console.log("platform validated",d);
return Percolate.getChannelV5({key: fd.key, channel: fd.channel})
},err => {
$scope.stopLoader()
$scope.showError("Invalid Platform ID");
})
.then(d => {
if (!d) return;
if (!d.data || !d.data.data) {
$scope.stopLoader()
$scope.showError("Invalid Channel ID");
return;
}

console.log("channel validated",d);

$scope.stopLoader();

// extend new channel object
angular.extend($scope.activeChannel, fd);
console.log('Submiting form, current dataset: ', $scope.activeChannel)
$state.go('add.topics')
},err => {
$scope.stopLoader()
$scope.showError("Invalid channel ID");
});

}


Expand Down
6 changes: 4 additions & 2 deletions frontend/scripts/settings/controllers/add.templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ angular.module('myApp')
key : $scope.activeChannel.key,
fields : {
'scope_ids': 'license:' + $scope.activeChannel.license,
'type': 'metadata'
'type': 'metadata',
'extend_scopes': true
}
})
.then(getMetadataPerco, apiError)
Expand Down Expand Up @@ -457,7 +458,8 @@ angular.module('myApp')
fields : {
'scope_ids': 'license:' + $scope.activeChannel.license,
'ext.platform_ids': $scope.activeChannel.platform,
'type': 'post'
'type': 'post',
'extend_scopes':true
}
})
.then(getTemplateSchemas, apiError)
Expand Down
6 changes: 4 additions & 2 deletions frontend/scripts/settings/controllers/add.topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ angular.module('myApp')
* -------------------------------------- */

function apiError (err) {
console.log('Error: ', err);
$scope.stopLoader()
$scope.showError(err)
return
Expand Down Expand Up @@ -96,7 +97,7 @@ angular.module('myApp')
function fetchPercolatUsers(paginationData) {
$scope.showLoader('Loading users from Percolate...')
$scope.percolateUsers = null
return Percolate.getUsersByLicense({
return Percolate.getUsersByLicenseV5({
key : $scope.activeChannel.key,
license: $scope.activeChannel.license,
fields : {
Expand Down Expand Up @@ -197,7 +198,7 @@ angular.module('myApp')
if( $scope.formData ) {
angular.extend($scope.activeChannel, $scope.formData)
}
// console.log('Submiting form, current dataset: ', $scope.activeChannel)
console.log('Submiting form, current dataset: ', $scope.activeChannel)
$state.go('add.templates')
}

Expand All @@ -216,6 +217,7 @@ angular.module('myApp')

// Check if we have the active User
if( !$scope.activeChannel.user ) {
console.log('No active users found');
$scope.showError('No active user found.')
$state.go('manage')
}
Expand Down
25 changes: 10 additions & 15 deletions frontend/views/templates/new-channel-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<label for="key">First, please enter your Percolate API key</label>
<input type="text" name="key" id="key" class="form-control"
ng-model="formData.key"
ng-change="checkKey()"
ng-class="{ 'has-error' : setupForm.key.$invalid && (!setupForm.key.$pristine || submitted) }" required>
</div>
Expand All @@ -29,29 +28,25 @@
</div>
<div class="form-group">
<label for="license">License</label>
<select name="license" id="license" class="form-control"
<label for="license">License ID</label>
<input type="text" name="license" id="license" class="form-control"
ng-model="formData.license"
ng-disabled="!licenses"
ng-change="changeLicense()"
ng-options="option.id as option.name for option in licenses" required></select>
ng-class="{ 'has-error' : setupForm.license.$invalid && (!setupForm.license.$pristine || submitted) }" required>
</div>
<div class="form-group">
<label for="platform">Platform</label>
<select name="platform" id="platform" class="form-control"
<label for="platform">Platform ID</label>
<input type="text" name="platform" id="platform" class="form-control"
ng-model="formData.platform"
ng-disabled="!platforms"
ng-change="changePlatform()"
ng-options="option.id as option.name for option in platforms" required></select>
ng-class="{ 'has-error' : setupForm.platform.$invalid && (!setupForm.platform.$pristine || submitted) }" required>
</div>
<div class="form-group">
<label for="channel">Channel</label>
<select name="channel" id="channel" class="form-control"
<label for="channel">Channel ID</label>
<input type="text" name="channel" id="channel" class="form-control"
ng-model="formData.channel"
ng-disabled="!channels"
ng-options="option.id as option.name for option in channels" required></select>
ng-class="{ 'has-error' : setupForm.channel.$invalid && (!setupForm.channel.$pristine || submitted) }" required>
</div>
<div class="form-group">
Expand Down
2 changes: 1 addition & 1 deletion frontend/views/templates/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

<p>
<small>
Plugin version: 4.x-1.2.7 (<i>Supported WordPress version - Plugin version</i>)<br>
Plugin version: 4.x-1.3.0 (<i>Supported WordPress version - Plugin version</i>)<br>
PHP >= 5.6 required for the plugin to function properly
</small>
</p>
2 changes: 1 addition & 1 deletion percolate-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Plugin URI: https://github.com/percolate/wordpress
Description: Percolate integration for Wordpress, which includes the ability to sync posts, media library elements and custom creative templates.
Author: Percolate Industries, Inc.
Version: 4.x-1.2.7
Version: 4.x-1.3.0
Author URI: http://percolate.com
*/

Expand Down

0 comments on commit a95f921

Please sign in to comment.