Skip to content

Commit

Permalink
Merge pull request #4 from TheDMSGroup/ENG-91-autocomplete-tokens
Browse files Browse the repository at this point in the history
[ENG-119] Initial codemirror support for Raw and other JS improvements.
  • Loading branch information
heathdutton authored Mar 1, 2018
2 parents 05e1534 + c098b60 commit 6e8a988
Show file tree
Hide file tree
Showing 15 changed files with 202 additions and 137 deletions.
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
.idea
composer.lock
# Standard .gitignore for a Mautic plugin.
.*
!.gitignore
!.htaccess
!.gitkeep
!.travis.yml
vendor
node_modules
62 changes: 62 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Standard .travis.yml for a Mautic plugin. Adjust env variables as needed.
env:
global:
# The exact plugin folder/bundle name.
- "MAUTIC_PLUGIN=MauticContactClientBundle"

dist: precise

language: php

services:
- mysql

php:
- 5.6.19
- 7.0
- 7.1

before_install:

# Create mautictest database.
- mysql -e 'CREATE DATABASE mautictest;'

# Turn off XDebug.
- phpenv config-rm xdebug.ini || return

# Install dependencies in parallel.
- travis_retry composer global require hirak/prestissimo

# Set to test environment for Symfony's commands in post install commands.
- export SYMFONY_ENV="test"

# Install PHPSTAN for PHP 7+
- if [[ ${TRAVIS_PHP_VERSION:0:3} != "5.6" ]]; then composer global require phpstan/phpstan-shim:0.8.5; fi

# Clone the latest core release.
- git clone -b master --single-branch --depth 1 https://github.com/mautic/mautic.git /tmp/mautic

# Combine core with our plugin.
- mkdir -p /tmp/mautic/plugins/$MAUTIC_PLUGIN
- rsync -r --delete-after --quiet $TRAVIS_BUILD_DIR/ /tmp/mautic/plugins/$MAUTIC_PLUGIN
- rsync -r --delete-after --quiet /tmp/mautic/ $TRAVIS_BUILD_DIR/

install:

# Install core dependencies.
- composer install

# Install plugin dependencies (if any).
- composer require wikimedia/composer-merge-plugin
- composer config extra.merge-plugin.include plugins/$MAUTIC_PLUGIN/composer.json

script:

# Run PHPUnit including core tests to find potential BC breaks.
- bin/phpunit --bootstrap vendor/autoload.php --configuration app/phpunit.xml.dist --fail-on-warning

# Run PHPSTAN analysis for PHP 7+ only in the scope of this plugin.
- if [[ ${TRAVIS_PHP_VERSION:0:3} != "5.6" ]]; then ~/.composer/vendor/phpstan/phpstan-shim/phpstan.phar analyse plugins/$MAUTIC_PLUGIN; fi

# Check code standards for PHP 7.1 only in the scope of this plugin.
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.1" ]]; then bin/php-cs-fixer fix -v --dry-run --diff plugins/$MAUTIC_PLUGIN; fi
2 changes: 1 addition & 1 deletion Assets/build/contactclient.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Assets/build/contactclient.min.js.map

Large diffs are not rendered by default.

77 changes: 37 additions & 40 deletions Assets/js/00.type.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,48 @@
// Logic for the payload type switch.
Mautic.contactclientType = function () {

if (typeof window.contactclientTypeLoaded === 'undefined') {
window.contactclientTypeLoaded = true;
// Trigger payload tab visibility based on contactClient type.
mQuery('input[name="contactclient[type]"]').change(function () {
var val = mQuery('input[name="contactclient[type]"]:checked').val();
if (val === 'api') {
mQuery('#payload-tab').removeClass('hide');
mQuery('.row.api_payload').removeClass('hide');
mQuery('.row.file_payload').addClass('hide');
// Trigger payload tab visibility based on contactClient type.
mQuery('input[name="contactclient[type]"]').change(function () {
var val = mQuery('input[name="contactclient[type]"]:checked').val();
if (val === 'api') {
mQuery('#payload-tab').removeClass('hide');
mQuery('.row.api_payload').removeClass('hide');
mQuery('.row.file_payload').addClass('hide');

// Mautic.contactclientApiPayload();
Mautic.contactclientApiPayloadPre();
}
else if (val === 'file') {
mQuery('#payload-tab').removeClass('hide');
mQuery('.row.api_payload').addClass('hide');
mQuery('.row.file_payload').removeClass('hide');
// Mautic.contactclientApiPayload();
Mautic.contactclientApiPayloadPre();
}
else if (val === 'file') {
mQuery('#payload-tab').removeClass('hide');
mQuery('.row.api_payload').addClass('hide');
mQuery('.row.file_payload').removeClass('hide');

Mautic.contactclientFilePayload();
}
else {
mQuery('#payload-tab').addClass('hide');
}
}).first().parent().parent().find('label.active input:first').trigger('change');

Mautic.contactclientFilePayload();
// Hide the right column when Payload tab is open to give more room for
// table entry.
var activeTab = '#details';
mQuery('.contactclient-tab').click(function () {
var thisTab = mQuery(this).attr('href');
if (thisTab !== activeTab) {
activeTab = thisTab;
if (activeTab === '#payload') {
// Expanded view.
mQuery('.contactclient-left').addClass('col-md-12').removeClass('col-md-9');
mQuery('.contactclient-right').addClass('hide');
}
else {
mQuery('#payload-tab').addClass('hide');
}
}).first().parent().parent().find('label.active input:first').trigger('change');

// Hide the right column when Payload tab is open to give more room for
// table entry.
var activeTab = '#details';
mQuery('.contactclient-tab').click(function () {
var thisTab = mQuery(this).attr('href');
if (thisTab !== activeTab) {
activeTab = thisTab;
if (activeTab === '#payload') {
// Expanded view.
mQuery('.contactclient-left').addClass('col-md-12').removeClass('col-md-9');
mQuery('.contactclient-right').addClass('hide');
}
else {
// Standard view.
mQuery('.contactclient-left').removeClass('col-md-12').addClass('col-md-9');
mQuery('.contactclient-right').removeClass('hide');
}
// Standard view.
mQuery('.contactclient-left').removeClass('col-md-12').addClass('col-md-9');
mQuery('.contactclient-right').removeClass('hide');
}
});
}
}
});
};

Mautic.contactclientTypeChange = function (t) {
Expand Down
22 changes: 22 additions & 0 deletions Assets/js/02.json_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,28 @@ JSONEditor.defaults.options.expand_height = true;

// Custom validators.
JSONEditor.defaults.custom_validators.push(function (schema, value, path) {
// When a textarea with option "codemirror" is true, render codemirror.
if (schema.format === 'textarea' && typeof schema.options !== 'undefined' && schema.options.codemirror === true) {
mQuery('textarea[name=\'' + path.replace('root.', 'root[').split('.').join('][') + ']\']:first:visible:not(.codemirror-checked)').each(function () {
var $input = mQuery(this);
editor = CodeMirror.fromTextArea($input[0], {
// mode: {
// name: 'javascript',
// json: true
// },
theme: 'material',
gutters: ['CodeMirror-lint-markers'],
// lint: 'json',
lintOnChange: true,
matchBrackets: true,
autoCloseBrackets: true,
lineNumbers: true,
extraKeys: {'Ctrl-Space': 'autocomplete'},
lineWrapping: true
});
}).addClass('codemirror-checked');
}
// Annual/fixed date support.
var errors = [];
if (schema.format === 'datestring') {
if (!/^[0-9|yY]{4}-[0-9]{1,2}-[0-9]{1,2}$/.test(value) && !/^[0-9]{1,2}-[0-9]{1,2}$/.test(value)) {
Expand Down
12 changes: 4 additions & 8 deletions Assets/js/03.api_payload.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// API Payload field.
// API Payload JSON Schema.
Mautic.contactclientApiPayloadPre = function () {
var $apiPayload = mQuery('#contactclient_api_payload');
if (typeof window.contactclientApiPayloadPreoaded === 'undefined' && $apiPayload.length) {

window.contactclientApiPayloadPreoaded = true;
var $apiPayload = mQuery('#contactclient_api_payload:first:not(.hide)');
if ($apiPayload.length) {

var tokenSource = 'plugin:mauticContactClient:getTokens';
if (typeof window.JSONEditor.tokenCache === 'undefined') {
Expand Down Expand Up @@ -35,10 +33,8 @@ Mautic.contactclientApiPayloadPre = function () {
};
Mautic.contactclientApiPayload = function () {

var $apiPayload = mQuery('#contactclient_api_payload');
if (typeof window.contactclientApiPayloadLoaded === 'undefined' && $apiPayload.length) {

window.contactclientApiPayloadLoaded = true;
var $apiPayload = mQuery('#contactclient_api_payload:first:not(.hide)');
if ($apiPayload.length) {

var apiPayloadCodeMirror,
apiPayloadJSONEditor;
Expand Down
6 changes: 2 additions & 4 deletions Assets/js/04.exclusive.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Exclusive field.
Mautic.contactclientExclusive = function () {
var $exclusive = mQuery('#contactclient_exclusive');
if (typeof window.contactclientExclusiveLoaded === 'undefined' && $exclusive.length) {

window.contactclientExclusiveLoaded = true;
var $exclusive = mQuery('#contactclient_exclusive:not(.hide):first');
if ($exclusive.length) {

var exclusiveJSONEditor;

Expand Down
6 changes: 3 additions & 3 deletions Assets/js/06.filter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// @todo - Filtering field.
Mautic.contactclientFilter = function () {
var $filter = mQuery('#contactclient_filter');
if (typeof window.contactclientFilterLoaded === 'undefined' && $filter.length) {
var $filter = mQuery('#contactclient_filter:not(.hide):first');
if ($filter.length) {


window.contactclientFilterLoaded = true;
}
};
6 changes: 2 additions & 4 deletions Assets/js/07.limits.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Limits field.
Mautic.contactclientLimits = function () {
var $limits = mQuery('#contactclient_limits');
if (typeof window.contactclientLimitsLoaded === 'undefined' && $limits.length) {

window.contactclientLimitsLoaded = true;
var $limits = mQuery('#contactclient_limits:not(.hide):first');
if ($limits.length) {

var limitsJSONEditor;

Expand Down
8 changes: 3 additions & 5 deletions Assets/js/08.schedule.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// Schedule - Hours of Operation.
Mautic.contactclientSchedule = function () {

var $scheduleHoursTarget = mQuery('#contactclient_schedule_hours_widget:first'),
$scheduleHoursSource = mQuery('#contactclient_schedule_hours:first');
if (typeof window.contactclientScheduleLoaded === 'undefined' && $scheduleHoursTarget.length && $scheduleHoursSource.length) {

window.contactclientScheduleLoaded = true;
var $scheduleHoursTarget = mQuery('#contactclient_schedule_hours_widget:not(.hide):first'),
$scheduleHoursSource = mQuery('#contactclient_schedule_hours:not(.hide):first');
if ($scheduleHoursTarget.length && $scheduleHoursSource.length) {

var operationTime = $scheduleHoursSource.val();
if (operationTime.length) {
Expand Down
109 changes: 52 additions & 57 deletions Assets/js/10.timeline.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,65 @@
Mautic.contactclientTimelineOnLoad = function (container, response) {

if (typeof window.contactclientTimelineLoaded === 'undefined') {

window.contactclientTimelineLoaded = true;

var codeMirror = function ($el) {
if (!$el.hasClass('codemirror-active')) {
var $textarea = $el.find('textarea.codeMirror-yaml');
if ($textarea.length) {
CodeMirror.fromTextArea($textarea[0], {
mode: 'yaml',
theme: 'material',
gutters: [],
lineNumbers: false,
lineWrapping: true,
readOnly: true
});
}
$el.addClass('codemirror-active');
}
};
mQuery('#contactclient-timeline a[data-activate-details=\'all\']').on('click', function () {
if (mQuery(this).find('span').first().hasClass('fa-level-down')) {
mQuery('#contactclient-timeline a[data-activate-details!=\'all\']').each(function () {
var detailsId = mQuery(this).data('activate-details'),
$details = mQuery('#timeline-details-' + detailsId);
if (detailsId && $details.length) {
$details.removeClass('hide');
codeMirror($details);
mQuery(this).addClass('active');
}
});
mQuery(this).find('span').first().removeClass('fa-level-down').addClass('fa-level-up');
}
else {
mQuery('#contactclient-timeline a[data-activate-details!=\'all\']').each(function () {
var detailsId = mQuery(this).data('activate-details'),
$details = mQuery('#timeline-details-' + detailsId);
if (detailsId && $details.length) {
$details.addClass('hide');
mQuery(this).removeClass('active');
}
var codeMirror = function ($el) {
if (!$el.hasClass('codemirror-active')) {
var $textarea = $el.find('textarea.codeMirror-yaml');
if ($textarea.length) {
CodeMirror.fromTextArea($textarea[0], {
mode: 'yaml',
theme: 'material',
gutters: [],
lineNumbers: false,
lineWrapping: true,
readOnly: true
});
mQuery(this).find('span').first().removeClass('fa-level-up').addClass('fa-level-down');
}
});
mQuery('#contactclient-timeline a[data-activate-details!=\'all\']').on('click', function () {
var detailsId = mQuery(this).data('activate-details');
if (detailsId && mQuery('#timeline-details-' + detailsId).length) {
var activateDetailsState = mQuery(this).hasClass('active'),
$el.addClass('codemirror-active');
}
};
mQuery('#contactclient-timeline a[data-activate-details=\'all\']').on('click', function () {
if (mQuery(this).find('span').first().hasClass('fa-level-down')) {
mQuery('#contactclient-timeline a[data-activate-details!=\'all\']').each(function () {
var detailsId = mQuery(this).data('activate-details'),
$details = mQuery('#timeline-details-' + detailsId);

if (activateDetailsState) {
$details.addClass('hide');
mQuery(this).removeClass('active');
}
else {
if (detailsId && $details.length) {
$details.removeClass('hide');
codeMirror($details);
mQuery(this).addClass('active');
}
}
});
});
mQuery(this).find('span').first().removeClass('fa-level-down').addClass('fa-level-up');
}
else {
mQuery('#contactclient-timeline a[data-activate-details!=\'all\']').each(function () {
var detailsId = mQuery(this).data('activate-details'),
$details = mQuery('#timeline-details-' + detailsId);
if (detailsId && $details.length) {
$details.addClass('hide');
mQuery(this).removeClass('active');
}
});
mQuery(this).find('span').first().removeClass('fa-level-up').addClass('fa-level-down');
}
});
mQuery('#contactclient-timeline a[data-activate-details!=\'all\']').on('click', function () {
var detailsId = mQuery(this).data('activate-details');
if (detailsId && mQuery('#timeline-details-' + detailsId).length) {
var activateDetailsState = mQuery(this).hasClass('active'),
$details = mQuery('#timeline-details-' + detailsId);

if (response && typeof response.timelineCount !== 'undefined') {
mQuery('#TimelineCount').html(response.timelineCount);
if (activateDetailsState) {
$details.addClass('hide');
mQuery(this).removeClass('active');
}
else {
$details.removeClass('hide');
codeMirror($details);
mQuery(this).addClass('active');
}
}
});

if (response && typeof response.timelineCount !== 'undefined') {
mQuery('#TimelineCount').html(response.timelineCount);
}
};
Loading

0 comments on commit 6e8a988

Please sign in to comment.