Project

General

Profile

1 8263 walker
Modifying and Creating Themes
2 8272 leinfelder
=============================
3 8263 walker
.. versionadded:: 2.2.0
4
5
.. contents::
6
7 9402 walker
Metacat's theming system, `MetacatUI <https://github.com/NCEAS/metacatui>`_, is deployed separately from Metacat, allowing more
8
independent user interface customization. Check the `MetacatUI GitHub <https://github.com/NCEAS/metacatui>`_ for the most up to date version.
9
10
MetacatUI is structured in a model-view-controller
11 8263 walker
architecture using `Backbone.js <http://www.backbonejs.org>`_. Some background knowledge on Backbone.js may be helpful for
12
advanced modification of MetacatUI, but is not necessary for editing the CSS styling and HTML of
13 8272 leinfelder
the included MetacatUI views.
14 8263 walker
15
.. figure:: images/screenshots/image007.png
16
17 8272 leinfelder
   MetacatUI's default home page. Users can customize the appearance using themes.
18 8263 walker
19
Quick Start Using the Default Theme
20 8272 leinfelder
-----------------------------------
21 8705 walker
The default theme can be used out-of-box. To make simple edits such as change the logo in the header or footer, add links to the navigation, etc., we will need to create a new theme, make our changes to the header and footer HTML templates, but borrow all other templates from the default theme so we don't have to create everything from scratch.
22 8263 walker
23 8705 walker
1. **Create a new theme:** Duplicate the ``js/themes/default`` directory and rename it to a unique theme name with no spaces.
24 8263 walker
25 8705 walker
2. **Add your logo:** In the ``js/themes/<yourtheme>/img`` directory, add the following image files:
26 8263 walker
27
	* Your organization's logo
28
	* Any supporter or donor logos to use in the footer
29
30 8705 walker
3. **Customize the header and footer:** Create a ``templates`` directory in ``js/themes/<yourtheme>`` and copy the following files from ``js/templates`` into
31 8263 walker
that new directory:
32
33
	* footer.html
34
	* navbar.html
35
36 8705 walker
3a. Open the ``js/themes/<yourtheme>/templates/footer.html`` file and change the footer logo image paths and the link paths to direct to
37 8263 walker
your new footer images and their corresponding web addresses. For example,
38
39
	::
40
41 8705 walker
	  <a href="http://nceas.ucsb.edu" target="_blank">
42
	  	<img alt="NCEAS" src="./js/themes/yourtheme/img/nceas-logo-white.png">
43
	  </a>
44 8263 walker
45 8705 walker
	You can add or modify any of the HTML in the footer; we are using the logo only as a simple demonstration.
46 8263 walker
47 8705 walker
3b. Similarly, open the ``js/themes/<yourtheme>/templates/navbar.html`` file and replace the Metacat logo file with your organization's logo file. You can also add more links to this header navigation.
48 8263 walker
49 8705 walker
4. **Create your theme map:** By default, Metacat will use the default theme templates unless you specifically tell Metacat to override these with the template files in your custom theme.
50
In the ``js/themes/<yourtheme>/config.js`` file, change the theme name on line 1, ``default``, to your chosen new theme name.
51
In the ``themeMap``, add a new line for every template you have edited and added to your new theme. An example for the footer.html and navbar.html files is below.
52 8706 walker
53
  ::
54 8263 walker
55 8705 walker
	var theme = theme || "default";
56
	var themeMap =
57
	{
58
		'*': {
59
			// example overrides are provided here
60
			'templates/navbar.html' : 'themes/' + theme + '/templates/navbar.html',
61
			'templates/footer.html' : 'themes/' + theme + '/templates/footer.html'
62
			}
63
	};
64 8263 walker
65 8705 walker
5. Repeat step 3-4 as necessary for any other template files you edit.
66
67 8706 walker
7. Open ``index.html``. Edit the following line to reflect your theme name (``data-theme``) and your Metacat
68
   context (``data-metacat-context``). (The Metacat context is the name of the directory in which Metacat is installed in the Tomcat web-application directory (most likely "metacat"). Whomever installed Metacat will know what this directory is called. If your MetacatUI is already successfully retrieving datasets during searches, this is already set and can be left as is.)
69 8705 walker
6. **Specify your theme and metacat context** Open ``index.html``. Edit the following line to specify your theme name (attribute ``data-theme``) and your Metacat
70 8706 walker
   context (attribute ``data-metacat-context``) (The Metacat context is the name of the directory in which Metacat is installed in the Tomcat web-application directory (most likely "metacat"). Whomever installed Metacat will know what this directory is called. If your MetacatUI is already successfully retrieving datasets during searches, this is already set and can be left as is.)
71 8705 walker
72 8263 walker
	::
73
74 8272 leinfelder
	  <script data-theme="default" data-metacat-context="metacat" id="loader" type="text/javascript" src="loader.js"></script>
75 8263 walker
76
77
Creating a Custom Theme
78 8272 leinfelder
-----------------------
79 8263 walker
All themes share the same CSS, HTML, JavaScript and image files. Any of these files can be customized by creating
80 8705 walker
a new theme and telling Metacat to override the default files with the ones in your custom theme.
81 8263 walker
82 8705 walker
1. **Create a new theme:** Copy an existing theme directory structure, found in ``js/themes``, and rename that directory after your new theme.
83 8263 walker
Notice that each theme directory looks something like this:
84
85
	::
86
87
	  css/
88
	  img/
89
	  routers/
90
	  templates/
91
	  config.js
92 8706 walker
93 8705 walker
2. **Style your theme** Add a CSS file to your theme by creating a CSS file in the ``js/themes/<yourtheme>/css/`` directory
94 8263 walker
   named ``metacatui.css``
95
96 8705 walker
3. **Add images** Add your custom images to the ``js/themes/<yourtheme>/img`` directory.
97 8263 walker
98 8705 walker
4. **Edit templates** Add HTML templates to the ``js/themes/<yourtheme>/templates`` directory.
99 8263 walker
100 8705 walker
5. **Create your theme map** Open the ``js/themes/<yourtheme>/config.js`` file. In here you will define your theme and themeMap. By default, Metacat will use the default theme templates unless you specifically tell Metacat to override these with the template files in your custom theme.
101 8263 walker
102
  ::
103
104
	var theme = theme || "default";
105
	var themeMap =
106
	{
107
		'*': {
108
			// example overrides are provided here
109
			//'views/AboutView' : 'themes/' + theme + '/views/AboutView.js',
110
			//'templates/navbar.html' : 'themes/' + theme + '/templates/navbar.html'
111
			}
112
	};
113
114 8705 walker
Change the theme name on line 1, ``default``, to your chosen new theme name. Then follow the commented out examples in ``themeMap`` to
115
explicitly tell Metacat which default shared files should be overridden with your custom theme
116 8263 walker
files. The pattern is:
117
118
	``path/originalFile.html : 'themes/' + theme + '/path/newFile.html'``
119
120 8705 walker
*Note: You do not have to override the CSS or image files.*
121 8263 walker
122 8705 walker
7. **Specify your theme and metacat context** Open ``index.html``. Edit the following line to specify your theme name (attribute ``data-theme``) and your Metacat
123
context (attribute ``data-metacat-context``):
124 8263 walker
125
	::
126
127 8272 leinfelder
	  <script data-theme="default" data-metacat-context="metacat" id="loader" type="text/javascript" src="loader.js"></script>
128 8263 walker
129
130
Changing the background images on the default theme
131 8272 leinfelder
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
132 8263 walker
The ``js/templates/app.html`` file contains the ``<img>`` element for the background image:
133
134
	::
135
136
	  <img src="" class="bg" id="bg_image" data-image-count="9" />
137
138
Change the ``data-image-count`` attribute to the number of images you would like to cycle through in your custom
139 8705 walker
theme. To have the same background image on all views, change this value to 1. To not use the background image at all, simply remove this ``<img>`` element.
140 8263 walker
141 8705 walker
Store your custom background image files in ``js/themes/<yourtheme>/img/backgrounds``. Keep the naming convention of ``bg1.jpg``, ``bg2.jpg``, etc., making sure
142
that all numbers from 1 to your specified total (``data-image-count``) are included. (i.e. do not skip any numbers, such as ``bg1.jpg``, ``bg3.jpg`` ...)
143 8263 walker
144
145
Advanced options for custom themes
146 8272 leinfelder
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
147 8705 walker
Advanced users can choose to override the JavaScript files for even more customization of MetacatUI.
148 8263 walker
149
150
The ``router.js`` file can be modified to render different views based on the URL. For example,
151
a theme which has no home page and routes users to the ``DataCatalogView`` view instead, would modify ``router.js``
152
like so:
153
154
	::
155
156
	  	// MetacatUI Router
157
		// ----------------
158
		var UIRouter = Backbone.Router.extend({
159
			routes: {
160 8705 walker
				'' 					        : 'routeToData',    // route ROOT to data
161
				'about'                     : 'renderAbout',
162
				'about(/:anchorId)'         : 'renderAbout',
163
				'plans'                     : 'renderPlans',
164
				'tools(/:anchorId)'         : 'renderTools',
165
				'data(/search/:searchTerm)(/page/:page)' : 'renderData',
166
				'view/*pid'                 : 'renderMetadata',
167
				'external(/*url)'           : 'renderExternal',
168
				'logout'                    : 'logout',
169
				'signup'          			: 'renderLdap',
170
				'account(/:stage)'          : 'renderLdap',
171
				'share'                     : 'renderRegistry'
172 8263 walker
			},
173
174
In this example, the index path, ``''``, was changed from
175
the value ``renderIndex`` which renders the ``IndexView.js`` view, to ``routeToData`` which reroutes to ``data``,
176
in turn rendering the ``DataCatalogView`` view.
177
178
	::
179
180
	  	routeToData: function () {
181
			console.log('Called UIRouter.routeToData()');
182
			this.navigate("data", {trigger: true});
183
		},
184
185 8705 walker
	**Note: Remember to include any views or routers in your list of overrides in js/themes/<yourtheme>/config.js
186 8263 walker
	for each file you modify**
187
188
189
For more information about ``Backbone.js``, see the Backbone.js documentation at `www.backbonejs.org <http://www.backbonejs.org>`_
190
191
192 9390 leinfelder
Using Custom Endpoints
193
-----------------------
194
MetacatUI can also be configured to use custom DataONE endpoints for both Member Node and Coordinating Node APIs.
195
The ``dataone`` theme shows an example of this endpoint customization in the ``AppModel.js`` file.
196
In custom themes, the AppModel.js values can be edited to suit your particular deployment needs.
197 8263 walker
198 9390 leinfelder
For querying the DataONE Coordinating Node, for example, the following properties would be set:
199
200
	::
201
202
	  	context: '',
203
		d1Service: "/cn/v2",
204
		d1CNBaseUrl:  "https://cn.dataone.org",
205
		d1CNService: "/cn/v2",
206
207
208
But querying a Metacat Member Node would be configured as:
209
210
	::
211
212
	  	context: '/metacat',
213
		d1Service: '/d1/mn/v2',
214
		d1CNBaseUrl: "https://cn.dataone.org/",
215
		d1CNService: "cn/v2",
216
217
218
219 8263 walker
Creating a Custom Skin
220
----------------------
221
.. deprecated:: 2.2.0
222 8272 leinfelder
   Use MetacatUI themes for any new UI development. Metacat's original skinning
223
   mechanism is still included and used for aspects of rendering metadata, but is
224
   not the preferred method for building web clients for Metacat.
225
226
   To MetacatUI themes, select ``metacatui`` as the default skin during skin configuration
227
   in the administration interface.
228 8263 walker
229
Skins are used in Metacat to customize the appearance of the search and display
230
web interface that is presented by Metacat.  Skins can be used to make a Metacat
231
instance exactly integrate into an existing web site, and are fully customizable.
232
233
To create and customize your own Metacat skin, you must first create a skin
234
directory. This is most easily accomplished by copying one of the existing skin
235
directories. Step-by-step directions for creating and installing a custom skin
236
are included below:
237
238 8272 leinfelder
1. Copy an existing skin directory. We recommend using the "default" directory.
239 8263 walker
240
  ::
241
242
    sudo cp -r <CONTEXT_DIR>/style/skins/default/ <CONTEXT_DIR>/style/skins/[yourSkin]/
243
244
  Where ``<CONTEXT_DIR>`` is the directory in which the Metacat application
245
  code lives  and ``[yourSkin]`` is the name you wish to apply to your skin.
246
247
2. In ``[yourSkin]`` directory, change all files named ``default.xxx`` to
248
   ``yourSkin.xxx``. The following files should be changed:
249
250
  ::
251
252
    default.css
253
    default.js
254
    default.properties
255
    default.properties.metadata.xml
256
    default.xml
257
258
3. In the metacat.properties file(``<CONTEXT_DIR>/WEB_INF/metacat.properties``),
259
   add ``[yourSkin]`` to the value of the skin.names property.
260
261
4. Restart Tomcat. Log in as the user that runs your Tomcat server (often "tomcat") and type:
262
263
  ::
264
265 9386 leinfelder
    /etc/init.d/tomcat7 restart
266 8263 walker
267
Navigate to Metacat's Configuration utility  and select the Configure Skins
268
option. Your custom skin should appear as a choice in the skins list. Change
269
the layout and style by modifying the header, footer, css, and other files in
270
your new skin directory.
271
272
It is important to note that all customized skins will be overwritten when
273
Metacat is reinstalled or upgraded. Please remember to back up your skins before
274
reinstalling or upgrading Metacat.