Skip to content

Commit

Permalink
see #1: refactor folder structure to make JavaScript files using the …
Browse files Browse the repository at this point in the history
…WordPress patterns
  • Loading branch information
ziodave committed Oct 27, 2015
1 parent 200e622 commit f774151
Show file tree
Hide file tree
Showing 11 changed files with 303 additions and 28 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
.idea/

/node_modules
/npm-debug.log
/build
25 changes: 25 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"boss": true,
"curly": true,
"eqeqeq": true,
"eqnull": true,
"es3": true,
"expr": true,
"immed": true,
"noarg": true,
"onevar": true,
"quotmark": "single",
"trailing": true,
"undef": true,
"unused": true,

"browser": true,

"globals": {
"_": false,
"Backbone": false,
"jQuery": false,
"JSON": false,
"wp": false
}
}
172 changes: 172 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/* jshint node:true */
module.exports = function ( grunt ) {
var path = require( 'path' ),
SOURCE_DIR = 'src/',
BUILD_DIR = 'build/',
autoprefixer = require( 'autoprefixer' ),
buildConfig = {},
builds = [ 'admin' ];

// Load tasks.
require( 'matchdep' ).filterDev( [ 'grunt-*', '!grunt-legacy-util' ] ).forEach( grunt.loadNpmTasks );

// Load legacy utils
grunt.util = require( 'grunt-legacy-util' );

builds.forEach( function ( build ) {
var path = SOURCE_DIR + 'admin/js/';
buildConfig[ build ] = { files: {} };
buildConfig[ build ].files[ path + build + '.js' ] = [ path + '/src/' + build + '.manifest.js' ];
} );

// Project configuration.
grunt.initConfig( {

clean: {
all: [ BUILD_DIR ],
dynamic: {
dot: true,
expand: true,
cwd: BUILD_DIR,
src: []
}
},
copy: {
files: {
files: [
{
dot: true,
expand: true,
cwd: SOURCE_DIR,
src: [ // Set here the files to include/exclude.
'**',
'!**/.git/**' // Ignore version control directories.
],
dest: BUILD_DIR
}
]
},
dynamic: {
dot: true,
expand: true,
cwd: SOURCE_DIR,
dest: BUILD_DIR,
src: []
}
},
browserify: buildConfig,
jshint: {
options: grunt.file.readJSON( '.jshintrc' ),
grunt: {
src: [ 'Gruntfile.js' ]
},
admin: {
options: {
browserify: true
},
src: [
SOURCE_DIR + 'admin/js/**/*.js'
]
}
},
uglify: {
options: {
ASCIIOnly: true
},
admin: {
expand: true,
cwd: SOURCE_DIR,
dest: BUILD_DIR,
ext: '.min.js',
src: [
'admin/js/helixware-mico-admin.js'
]
}
},
jsvalidate: {
options: {
globals: {},
esprimaOptions: {},
verbose: false
},
build: {
files: {
src: BUILD_DIR + '{admin,public}/js/**/*.js'
}
}
},
imagemin: {
core: {
expand: true,
cwd: SOURCE_DIR,
src: '{admin,public}/images/**/*.{png,jpg,gif,jpeg}',
dest: SOURCE_DIR
}
},
_watch: {
all: {
files: [
SOURCE_DIR + '**',
'!' + SOURCE_DIR + 'admin/js/src/**',
// Ignore version control directories.
'!' + SOURCE_DIR + '**/.git/**'
],
tasks: [ 'clean:dynamic', 'copy:dynamic' ],
options: {
dot: true,
spawn: false,
interval: 2000
}
},
config: {
files: 'Gruntfile.js'
}
}

} );


grunt.renameTask( 'watch', '_watch' );

grunt.registerTask( 'watch', function () {
if ( !this.args.length || this.args.indexOf( 'browserify' ) > -1 ) {
grunt.config( 'browserify.options', {
browserifyOptions: {
debug: true
},
watch: true
} );

grunt.task.run( 'browserify' );
}

grunt.task.run( '_' + this.nameArgs );
} );

// Default task.
grunt.registerTask('default', ['build']);

/*
* Automatically updates the `:dynamic` configurations
* so that only the changed files are updated.
*/
grunt.event.on('watch', function( action, filepath, target ) {
var src;

if ( [ 'all', 'rtl', 'browserify' ].indexOf( target ) === -1 ) {
return;
}

src = [ path.relative( SOURCE_DIR, filepath ) ];

if ( action === 'deleted' ) {
grunt.config( [ 'clean', 'dynamic', 'src' ], src );
} else {
grunt.config( [ 'copy', 'dynamic', 'src' ], src );

if ( target === 'rtl' ) {
grunt.config( [ 'rtlcss', 'dynamic', 'src' ], src );
}
}
});
};
33 changes: 33 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "helixware-mico",
"version": "1.3.0-dev",
"description": "HelixWare MICO Extensions for WordPress extends the HelixWare plugin with MICO features such as video segmentation, face detection, speech-to-text and more.",
"repository": {
"type": "git",
"url": "https://github.com/insideout10/helixware-mico-plugin.git"
},
"author": "Insideout10",
"license": "GPL-2.0+",
"devDependencies": {
"autoprefixer": "~6.0.3",
"grunt": "~0.4.5",
"grunt-browserify": "~4.0.1",
"grunt-contrib-clean": "~0.6.0",
"grunt-contrib-compress": "~0.13.0",
"grunt-contrib-concat": "~0.5.1",
"grunt-contrib-copy": "~0.8.0",
"grunt-contrib-cssmin": "~0.12.3",
"grunt-contrib-imagemin": "~0.9.4",
"grunt-contrib-jshint": "~0.11.3",
"grunt-contrib-qunit": "~0.7.0",
"grunt-contrib-uglify": "~0.9.2",
"grunt-contrib-watch": "~0.6.1",
"grunt-includes": "~0.5.1",
"grunt-jsvalidate": "~0.2.2",
"grunt-legacy-util": "^0.2.0",
"grunt-postcss": "~0.6.0",
"grunt-rtlcss": "~1.6.0",
"grunt-sass": "~1.0.0",
"matchdep": "~0.3.0"
}
}
60 changes: 33 additions & 27 deletions src/admin/class-helixware-mico-template-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,6 @@ public function __construct() {
'admin_footer_upload'
) );

add_action( 'admin_footer-post.php', array(
$this,
'admin_footer_post'
) );

}

public function admin_footer_post() {

echo <<<EOF
<script type="text/javascript">
alert('Hello!');
</script>
EOF;

var_dump( get_post() );
wp_die();

}

public function admin_footer_upload() {
Expand All @@ -43,7 +23,13 @@ public function admin_footer_upload() {
<script type="text/html" id="tmpl-helixware-mico-attachment-details-two-column">
<div class="attachment-media-view {{ data.orientation }}">
<div class="thumbnail thumbnail-{{ data.type }}">
HelixWare

<a class='nav-tab nav-tab-active' href='#tab-1'>Chapters</a>
<a class='nav-tab' href='#tab-2'>Faces</a>

<# _.each(data.faceDetectionFragments, function(fragment){ #>
{{fragment.start}}
<# }); #>
</div>
</div>
<div class="attachment-info">
Expand Down Expand Up @@ -166,16 +152,36 @@ public function admin_footer_upload() {
wp.template('attachment-details-two-column'),
wp.template('helixware-mico-attachment-details-two-column')
];

view = this;

// Load the face fragments.
wp.ajax.post('hw_face_detection_fragments', {id: this.model.get('id')}).done(function (fragments) {
view.model.set({faceDetectionFragments: fragments});
// Finally render.
view.render();
}).fail(function () {
// controller.trigger('hw:media:attachment:facefragments');
});


},
render: function () {

// Choose the template according to the mime type.
this.template = helixware.isHelixWare(this.model.get('mime'))
? this.templates[1]
: this.templates[0];
// If it's not a HelixWare asset, just call the superclass
// render method on the standard template.
if (!helixware.isHelixWare(this.model.get('mime'))) {
this.template = this.templates[0];
// Call the superclass render.
TwoColumn.__super__.render.apply(this, arguments);
return;
}

// Set the HelixWare template.
this.template = this.templates[1];

// Call the superclass render.
TwoColumn.__super__.render.apply(this, arguments);
console.log(this.model);
TwoColumn.__super__.render.apply(view, arguments);

}

Expand Down
10 changes: 10 additions & 0 deletions src/admin/js/admin.js

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

5 changes: 5 additions & 0 deletions src/admin/js/src/admin.manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var $ = jQuery;

var helixware = window.helixware = window.helixware || {};

helixware.controller.Test = require( './controllers/test-controller.js' );
1 change: 1 addition & 0 deletions src/admin/js/src/controllers/test-controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var x = 10;
17 changes: 17 additions & 0 deletions src/includes/class-helixware-mico-face-detection-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,21 @@ public function __construct( $hal_client, $server_url, $asset_service ) {

}

/**
* Handles the AJAX end-point _hw_face_detection_fragments_ providing the list
* of face detection fragments for the attachment with the id specified in the
* _id_ GET parameter.
*
* @since 1.3.0
*/
public function ajax_face_detection_fragments() {

if ( ! isset( $_REQUEST['id'] ) || ! is_numeric( $_REQUEST['id'] ) ) {
wp_send_json_error( 'The id parameter is required.' );
}

wp_send_json( $this->get_fragments_by_id( (int) $_REQUEST['id'] ) );

}

}
2 changes: 1 addition & 1 deletion src/includes/class-helixware-mico-fragment-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @subpackage Helixware_Mico/includes
* @author David Riccitelli <[email protected]>
*/
class Helixware_Mico_Fragment_Service {
abstract class Helixware_Mico_Fragment_Service {

const FIND_BY_ASSET_GUID_PATH = '/%s/search/findByAssetGUID?guid=%s';

Expand Down
2 changes: 2 additions & 0 deletions src/includes/class-helixware-mico.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ private function define_admin_hooks() {

$this->loader->add_action( 'wp_ajax_hw_vtt_chapters', $this->sequence_service, 'ajax_vtt_chapters' );

$this->loader->add_action( 'wp_ajax_hw_face_detection_fragments', $this->face_detection_service, 'ajax_face_detection_fragments' );

// Hook the requirements service.
$this->loader->add_action( 'admin_init', $this->requirements_service, 'admin_init' );

Expand Down

0 comments on commit f774151

Please sign in to comment.