-
Notifications
You must be signed in to change notification settings - Fork 34
(DEPRECATED) Developing POPUP widgets
Corey Peterson edited this page Dec 12, 2024
·
1 revision
- Install Materia if you haven't already!
- Create a new project on clu in the Materia namespace for your widget (i.e. "Stroop Effect").
- Clone the popup-template project in your-materia/static/sandbox/source
- Change the folder name of popup-template to match the name of your project (i.e. "stroop-effect")
- Edit the install.yaml file and change the name from "Popup Template" to your project (i.e. "Stroop Effect")
- Clone the popup-example project in your-materia/static/sandbox/source
- cd into the sandbox folder and build the popup-example project with grunt:
grunt --widget=popup-example sandbox
- In your browser navigate to
http://localhost:8080/sandbox/popup-example/demo
to view the Popup Example widget. This goes over some examples of how to create a popup widget. You can go through this widget along with its source code (again in your-materia/static/sandbox/source/popup-example) to see how it was created.
- Put the older flash wigt file in your root Materia folder (the actual location is irrelevant but putting the file here will make our commands easier)
- If you have PHP installed on your machine navigate in the command line to your root Materia folder and run this command to install the widget:
php oil r widget:install -u -f the-flash-widget.wigt
. - If you don't have PHP installed on your machine ssh into your vagrant machine with
vagrant ssh
, then navigate to the root Materia folder withcd /mnt/host/current
, then run the install command:php oil r widget:install -u -f the-flash-widget.wigt
- Create a new instance of this widget by running
php oil r widget:create_instance -i
and follow the prompts. For the user you'll want to use "~author", and when it asks you to create a stub qset you'll need to answer yes. - This will install the widget to your local Materia install. Navigate to 'My Widgets' to see the installed widget. You can use this widget as a reference.
- cd into the sandbox folder and watch your project with grunt:
grunt --widget=your-widget watch --minify-assets=false --minify-html=false
. This will watch your project source folder for changes and update the widget when you save a new file. The additional minify flags will disable minification which will help make debugging easier. - Edit your project source folder in your favorite text editor. HEY, LISTEN: Don't edit any files inside the sandbox/your-project folder, only edit the files in sandbox/source/your-project. The grunt task will overwrite any files in sandbox/your-project.
- View your project at
http://localhost:8080/sandbox/your-project/demo
.
POPUP widgets utilize the storage feature of Materia, which allows arbitrary data to be stored along with the widget and the user who is taking the widget. This data, represented in the form of a "Table" (much like SQLite) can then be used in Psychology classes as a data source to analyze. Every POPUP widget uses this feature to store all kinds of data (reaction times, survey responses, etc). Here's how to get started:
- Take a look at the old Flash source code for the text
storage.addTable
andstorage.insert
. In Flash this is how the developers store data with the widget.storage.addTable
creates a new table (if it doesn't exist).storage.insert
adds data to that table. - Now take a look at the widget-app.coffee file in the popup-example project. You should see
MateriaService.createStorageTable
andMateriaService.insertStorageRow
. This is the angular way to create tables and insert data into them. The syntax is slightly different, so here's a comparison:
-
Flash (old):
storage.addTable('ExampleTable', 'ReactionTime', 'KeyPressed');
-
Angular (new):
MateriaService.createStorageTable('ExampleTable', ['ReactionTime', 'KeyPressed']);
This will create a table called ExampleTable with the fields 'ReactionTime' and 'KeyPressed'.
-
Flash (old):
storage.insert('ExampleTable', foo, bar);
-
Angular (new):
MateriaService.insertStorageRow('ExampleTable', [foo, bar]);
This will add the values of foo and bar for the ReactionTime and KeyPressed fields to a new row in ExampleTable.
- Typically you'll want some sort of data object either in a controller you create or in the widgetCtrl to store the data you care about. Your widget will then add stuff to that data object, then use the MateriaService to create the storage table and insert your data into it. You can see an example inside widget-app.coffee of the popup-example project.
- You'll need to look inside the Flash code to determine what data to send and how to calculate that data.
- When you have inserted all the data you need to you'll want to call
MateriaService.widgetCompleted()
- this tells Materia that the user has finished the widget and will send all of the data to Materia. - While developing your widget you can call
MateriaService.getStorageTableValues
to test the table. If you created a table called "ExampleTable" you could callconsole.log(MateriaService.getStorageTableValues('ExampleTable'));
to test this. Of course you won't want to leave any console.log statements in your code as you finish developing your widget!
- When you're near completion you'll want to install the widget to fully test the final project (and make sure the storage data works). Navigate into your sandbox folder and build your widget with
grunt --widget=your-widget package
, then navigate to the root Materia folder and install it withphp oil r widget:install -u -f static/widget/sandbox/source/your-project/_output/your-project.wigt
- Now you'll need to create an instance of your widget. To do this run
php oil r widget:create_instance -i
and follow the prompts. For the user you'll want to use "~author", and when it asks you to create a stub qset you'll need to answer yes. - Navigate to your Materia install in your browser and find the instance you created in the previous step. Copy the link and test your widget (don't use Preview mode - this won't save storage data). Once you've tested your widget refresh the page and select your widget again - you should see a 'Data' tab with the storage data that your widget saved. You'll want to make sure your data is what you expect and matches the Flash widget (Zach can provide you with a sample of the data for the Flash widgets).