Skip to content

Instantly share code, notes, and snippets.

View anghelalexandra's full-sized avatar

Alexandra Anghel anghelalexandra

View GitHub Profile
@anghelalexandra
anghelalexandra / main.js
Created June 10, 2017 19:03
wp-pwa-sample-add-global-configuration
View main.js
const fetchConfig = () => {
const $initInjector = angular.injector(['ng']);
const $http = $initInjector.get('$http');
const $window = $initInjector.get('$window');
return $http.get(`${$window.__APPTICLES_BOOTSTRAP_DATA__.CONFIG_PATH}`);
};
...
fetchConfig()
@anghelalexandra
anghelalexandra / config.json
Created June 10, 2017 19:10
wp-pwa-sample-configuration
View config.json
{
"export": {
"categories": {
"find": "//pwathemes.com/demo-api/wp-json/wp/v2/categories",
"findOne": "//pwathemes.com/demo-api/wp-json/wp/v2/categories"
},
"posts": {
"find": "//pwathemes.com/demo-api/wp-json/wp/v2/posts",
"findOne": "//pwathemes.com/demo-api/wp-json/wp/v2/posts"
}
@anghelalexandra
anghelalexandra / api.service.js
Created June 10, 2017 19:14
wp-pwa-sample-api-service
View api.service.js
'use strict';
angular.module('appticles.api').factory('AppticlesAPI', AppticlesAPI);
AppticlesAPI.$inject = ['$log', '$http', 'configuration'];
/**
* @ngdoc service
* @name appticles.api.AppticlesAPI
*
@anghelalexandra
anghelalexandra / categories.controller.js
Last active June 10, 2017 19:24
wp-pwa-sample-read-categories
View categories.controller.js
class Categories {
constructor($log, AppticlesAPI) {
const populateCategories = (result) => {
this.categories = result;
};
AppticlesAPI.findCategories({hide_empty: 1})
.then(populateCategories)
.catch($log.error);
@anghelalexandra
anghelalexandra / categories.template.js
Created June 10, 2017 19:26
wp-pwa-sample-display-categories
View categories.template.js
<ion-view view-title="Progressive Web App Sample" cache-view="false">
<ion-content>
<ion-list>
<div
ng-repeat="category in categoriesVm.categories">
<p data-ng-bind-html="category.name | TrustHtmlFilter"></p>
</div>
</ion-list>
</ion-content>
</ion-view>
@anghelalexandra
anghelalexandra / validation.service.js
Created June 10, 2017 19:36
wp-pwa-sample-validate-categories
View validation.service.js
angular.module('appticles.validation')
.factory('AppticlesValidation', AppticlesValidation);
/**
* @ngdoc service
* @name appticles.validation.AppticlesValidation
*
* @description Service for validating data coming from the API.
*/
@anghelalexandra
anghelalexandra / categories.controller.js
Created June 10, 2017 19:45
wp-pwa-sample-reading-and-validating-categories
View categories.controller.js
class Categories {
constructor($log, $q, AppticlesAPI, AppticlesValidation) {
const validateCategories = (result) => {
let validatedCategories = AppticlesValidation.validateCategories(result);
return $q.when(validatedCategories);
};
const populateCategories = (result) => {
if (angular.isUndefined(result.error)) {
@anghelalexandra
anghelalexandra / categories.module.js
Created June 10, 2017 19:48
wp-pwa-sample-categories-module
View categories.module.js
angular.module('appticles.categories', [
'ui.router',
'appticles.api',
'appticles.configuration'
])
.config(['$stateProvider', '$urlRouterProvider', ($stateProvider, $urlRouterProvider) => {
$stateProvider
.state('categories', {
url: '/categories',
controller: 'CategoriesController as categoriesVm',
@anghelalexandra
anghelalexandra / index.php
Last active June 11, 2017 06:32
wp-pwa-sample-index-file
View index.php
<!DOCTYPE HTML>
<html manifest="" <?php language_attributes(); ?>>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-touch-fullscreen" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="mobile-web-app-capable" content="yes" />
View woocommerce-proxy.php
<?php
use Automattic\WooCommerce\Client;
class Custom_Endpoints_Woocommerce_API
{
protected function get_client() {
return new Client(
get_site_url(),
'woocommerce_consumer_key',
'woocommerce_consumer_secret',