Skip to content

Commit

Permalink
Changed where stuff compiled
Browse files Browse the repository at this point in the history
  - css now compiles to /css instead of /client/dist/css
Css is now loaded via themedCSS in the template
Javascript requirements now load in using the module name, not the path
Updated gitattributes
  • Loading branch information
mak001 committed Sep 28, 2017
1 parent 320694d commit ec3ffd8
Show file tree
Hide file tree
Showing 15 changed files with 114 additions and 91 deletions.
17 changes: 16 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
# tests
/tests export-ignore
/phpunit.xml.dist export-ignore
/phpcs.xml.dist export-ignore

# js related stuff
/.eslint export-ignore
/package.json export-ignore
/package-lock.json export-ignore
/webpack.config.dev.js export-ignore
/webpack.config.prod.js export-ignore
/client/src export-ignore
/client/tests export-ignore

# other
/.gitignore export-ignore
/.travis.yml export-ignore
/client/src export-ignore
/.scrutinizer.yml export-ignore
/.editorconfig export-ignore
1 change: 0 additions & 1 deletion client/dist/css/main.css.map

This file was deleted.

36 changes: 20 additions & 16 deletions client/dist/js/main.js

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

2 changes: 1 addition & 1 deletion client/dist/js/main.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/js/map.js.map

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

2 changes: 1 addition & 1 deletion client/dist/js/vendor.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
/******/ if (__webpack_require__.nc) {
/******/ script.setAttribute("nonce", __webpack_require__.nc);
/******/ }
/******/ script.src = __webpack_require__.p + "js/" + chunkId + ".js";
/******/ script.src = __webpack_require__.p + "client/dist/js/" + chunkId + ".js";
/******/ var timeout = setTimeout(onScriptComplete, 120000);
/******/ script.onerror = script.onload = onScriptComplete;
/******/ function onScriptComplete() {
Expand Down
2 changes: 1 addition & 1 deletion client/dist/js/vendor.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions client/src/js/components/list/Location.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class Location extends Component {
* @return Boolean | String
*/
getDistance() {
const { location, search } = this.props;
const { location } = this.props;
const distance = location.Distance;

if (distance === 0 && !search) {
if (distance === -1) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions client/dist/css/main.css → css/locator.css

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

1 change: 1 addition & 0 deletions css/locator.css.map

Large diffs are not rendered by default.

58 changes: 31 additions & 27 deletions src/objects/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public function getCoords()
* custom labels for fields
*
* @param bool $includerelations
*
* @return array|string
*/
public function fieldLabels($includerelations = true)
Expand All @@ -137,6 +138,7 @@ public function fieldLabels($includerelations = true)
$labels['Category.Name'] = 'Category';
$labels['Category.ID'] = 'Category';
$labels['Featured.NiceAsBoolean'] = 'Featured';

return $labels;
}

Expand All @@ -145,38 +147,37 @@ public function fieldLabels($includerelations = true)
*/
public function getCMSFields()
{
$fields = parent::getCMSFields();

$fields->removeByName(array(
'Import_ID',
));

$fields->dataFieldByName('Website')
->setAttribute('placeholder', 'http://');

$fields->replaceField('Email', EmailField::create('Email'));

$fields->replaceField(
'CategoryID',
DropdownField::create('CategoryID', 'Category', LocationCategory::get()->map())->setEmptyString('')
);

$featured = $fields->dataFieldByName('Featured')
->setDescription('Location will display near the top of the results list');
$fields->insertAfter(
$featured,
'CategoryID'
);

// allow to be extended via DataExtension
$this->extend('updateLocationFields', $fields);

return $fields;
// so it can easily be extended - concept taken from the blog module
$this->beforeUpdateCMSFields(function ($fields) {
$fields->removeByName(array(
'Import_ID',
));

$fields->dataFieldByName('Website')
->setAttribute('placeholder', 'http://');

$fields->replaceField('Email', EmailField::create('Email'));

$fields->replaceField(
'CategoryID',
DropdownField::create('CategoryID', 'Category', LocationCategory::get()->map())->setEmptyString('')
);

$featured = $fields->dataFieldByName('Featured')
->setDescription('Location will display near the top of the results list');
$fields->insertAfter(
$featured,
'CategoryID'
);
});

return parent::getCMSFields();
}

/**
* @param null $member
* @param array $context
*
* @return bool
*/
public function canView($member = null, $context = [])
Expand All @@ -187,6 +188,7 @@ public function canView($member = null, $context = [])
/**
* @param null $member
* @param array $context
*
* @return bool|int
*/
public function canEdit($member = null, $context = [])
Expand All @@ -197,6 +199,7 @@ public function canEdit($member = null, $context = [])
/**
* @param null $member
* @param array $context
*
* @return bool|int
*/
public function canDelete($member = null, $context = [])
Expand All @@ -207,6 +210,7 @@ public function canDelete($member = null, $context = [])
/**
* @param null $member
* @param array $context
*
* @return bool|int
*/
public function canCreate($member = null, $context = [])
Expand Down
60 changes: 30 additions & 30 deletions src/pages/Locator.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,36 +79,36 @@ class Locator extends Page
*/
public function getCMSFields()
{
$fields = parent::getCMSFields();

// Settings
$fields->addFieldsToTab('Root.Settings', array(
HeaderField::create('DisplayOptions', 'Display Options', 3),
OptionsetField::create('Unit', 'Unit of measure', array(
'm' => 'Miles',
'km' => 'Kilometers'
), 'm'),
DropdownField::create('Clusters', 'Use clusters?', array(
'false' => 'No',
'true' => 'Yes'
), 'false'),
));

// Filter categories
$config = GridFieldConfig_RelationEditor::create();
$config->removeComponentsByType('GridFieldAddExistingAutocompleter');
$config->addComponent(new GridFieldAddExistingSearchButton());
$categories = $this->Categories();
$categoriesField = GridField::create('Categories', 'Categories', $categories, $config)
->setDescription('only show locations from the selected category');

// Filter
$fields->addFieldsToTab('Root.Filter', array(
HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3),
$categoriesField,
));

return $fields;
// so it can easily be extended - concept taken from the blog module
$this->beforeUpdateCMSFields(function($fields) {
// Settings
$fields->addFieldsToTab('Root.Settings', array(
HeaderField::create('DisplayOptions', 'Display Options', 3),
OptionsetField::create('Unit', 'Unit of measure', array(
'm' => 'Miles',
'km' => 'Kilometers'
), 'm'),
OptionsetField::create('Clusters', 'Use clusters?', array(
'false' => 'No',
'true' => 'Yes'
), 'false'),
));

// Filter categories
$config = GridFieldConfig_RelationEditor::create();
$config->removeComponentsByType('GridFieldAddExistingAutocompleter');
$config->addComponent(new GridFieldAddExistingSearchButton());
$categories = $this->Categories();
$categoriesField = GridField::create('Categories', 'Categories', $categories, $config)
->setDescription('only show locations from the selected category');

// Filter
$fields->addFieldsToTab('Root.Filter', array(
HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3),
$categoriesField,
));
});
return parent::getCMSFields();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions templates/Dynamic/Locator/Layout/Locator.ss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

</div>

<% require javascript('locator/client/dist/js/vendor.js') %>
<% require javascript('locator/client/dist/js/main.js') %>
<% require javascript('dynamic/silverstripe-locator:client/dist/js/vendor.js') %>
<% require javascript('dynamic/silverstripe-locator:client/dist/js/main.js') %>
<%-- TODO - make optional? --%>
<% require css('locator/client/dist/css/main.css') %>
<% require themedCSS('locator') %>
8 changes: 4 additions & 4 deletions webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Path = require('path');
const paths = {
srcJs: Path.resolve('client', 'src', 'js'),
srcSass: Path.resolve('client', 'src', 'scss'),
dist: Path.resolve('client', 'dist'),
dist: Path.resolve(''),
};

module.exports = {
Expand All @@ -17,7 +17,7 @@ module.exports = {
},
output: {
path: paths.dist,
filename: Path.join('js', '[name].js'),
filename: Path.join('client', 'dist', 'js', '[name].js'),
},
devtool: 'source-map',
resolve: {
Expand Down Expand Up @@ -86,7 +86,7 @@ module.exports = {
test: /\.(png|gif|jpe?g|svg)$/,
loader: 'file-loader',
options: {
name: Path.join('images', '[name].[ext]'),
name: Path.join('client', 'dist', 'images', '[name].[ext]'),
},
},
],
Expand All @@ -102,6 +102,6 @@ module.exports = {
// move any modules inside "node_modules" to inside the vendor dist file
minChunks: module => module.context && module.context.indexOf('/node_modules/') > -1,
}),
new ExtractTextPlugin({ filename: Path.join('css', 'main.css'), allChunks: true }),
new ExtractTextPlugin({ filename: Path.join('css', 'locator.css'), allChunks: true }),
],
};
2 changes: 1 addition & 1 deletion webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ module.exports = {
// move any modules inside "node_modules" to inside the vendor dist file
minChunks: module => module.context && module.context.indexOf('/node_modules/') > -1,
}),
new ExtractTextPlugin({ filename: Path.join('css', 'main.css'), allChunks: true }),
new ExtractTextPlugin({ filename: Path.join('css', 'locator.css'), allChunks: true }),
],
};

0 comments on commit ec3ffd8

Please sign in to comment.