Creating a component for achieving an n-times running loop in Open Event Frontend

This blog article will illustrate how to to make a component in ember JS which allows you to iterate over a block of statements n-times which is being used in Open Event Frontend This is of great utility as the default ‘each’ helper of ember only allows us to iterate over objects and arrays, and not simply as a loop.So we begin by generating a component and calling it `n-times` and it is currently being used in the open event front-end project. Even before implementing it, it is obvious to us that the content inside the loop can be any thing and the component should be able to iterate over them repeatedly. Thus this component will need to have a {{yield}} block inside it, and thus will always have to be used in block form, to allow the user to enter the content that we need to iterate over. We begin by simply generating the boiler plate code of the component via Ember CLI. $ ember generate component n-times Now we proceed with the js code of the component. The only thing we need to ensure here is that no extra html tags are introduced because of our component, else it might break the flow of tags or disrupt the styling. Hence we make use of the tagName property to achieve the same. The final code looks something like this: import Ember from 'ember'; const { Component } = Ember; export default Component.extend({ tagName: '' }); We just needed to make the tagName none as we don’t want an extra div. And this is the template code for the same component For the template part we simply enclose the {{yield}} block inside each loop, and the value of times is expected to be passed at the time of calling the component. {{#each (range 0 times) as |number|}} {{yield number}} {{/each}} An important thing to note, we cannot have made this as a helper because the block form of helpers has been deprecated since Ember has updated hence component was the obvious choice. This may now be simply used as {{#n-times times=5}} {{ui-checkbox label=(t 'Create')}} {{ui-checkbox label=(t 'Read')}} {{ui-checkbox label=(t 'Update')}} {{ui-checkbox label=(t 'Delete')}} {{/n-times}}   Resources Official Semantic UI - ember Integration Ember JS- components Ember- Each helper *Featured image is captured by the author of this post, it is under public domain without any restrictions.

Continue ReadingCreating a component for achieving an n-times running loop in Open Event Frontend

Using ember semantic UI radio buttons to render form elements selectively on Open Event Front End

This blog article will illustrate how ember semantic ui radio buttons have been used to render form elements selectively on Open Event Front End and in the process will learn, how to make use of the powerful binding features offered by ember semantic ui for radio buttons via the mut action. So what do we have to begin with ? The sample form which we want to create What we want is that the radio button should allow us to make a choice and then display the corresponding  fields. Now that seems a trivial process, but there is some thought process which goes into this, to end up with the most efficient choice. So first just make the basic form where in all the fields are visible. Now let’s learn how to make use of the mut action on the radio buttons. What it allows us to do is pass a parameter while calling it, and that parameter name is shared by all the radio buttons belonging to a particular group of radio buttons. And what that action does is, store the name of the currently selected radio button in it. So we can easily keep track of which button has been selected and use that variable in selective rendering of templates. The action is triggered whenever the radio button’s property changes and the trigger is aptly called onChange. So essentially the syntax boils down to this : <!-- The first radio button --> {{ui-radio label=(t 'Sandbox mode - Used during development and testing') name='paypal_integration_mode' value='sandbox' onChange=(action (mut selectedMode))}} <!-- The second radio button --> {{ui-radio label=(t 'Live mode - Used during production') name='paypal_integration_mode' value='live' onChange=(action (mut selectedMode))}} Now whichever button is selected it’s name will be stored in selectedMode in this case. And hence we can use the conditional helpers of handle bars to render elements based on the selected radio button. The final code looks something like this:   <.h3 class="ui header">{{t 'PayPal Credentials'}}<./h3>     <.div class="sub header"> {{t 'See here on how to obtain these keys.'}}     <./div>    <.h5 class="ui header">{{t 'PayPal Integration Mode'}}<./h5>    <.div class="field">      {{ui-radio label=(t 'Sandbox mode') name='paypal_integration_mode' value='sandbox' current='sandbox' onChange=(action (mut selectedMode))}}    <./div>    {{#unless (eq selectedMode 'live')}}      <.div class="field">        <.label>{{t 'Sandbox username'}}<./label>        {{input type='text' name='sandbox_username'}}      <./div>      <.div class="field">        <.label>{{t 'Sandbox password'}}<./label>        {{input type='password' name='sandbox_password'}}      <./div>      <.div class="field">        <.label>{t 'Sandbox signature'}}<./label>        {{input type='text' name='sandbox_signature'}}      <./div>    {{/unless}}    <.div class="field">      {{ui-radio label=(t 'Live mode') name='paypal_integration_mode' value='live' onChange=(action (mut selectedMode))}}    <./div>    {{#if (eq selectedMode 'live')}}      <.div class="field">       <.label>{{t 'Live username'}}<./label>        {{input type='text' name='live_username'}}      <./div>      <.div class="field">        <.label>{{t 'Live password'}}<./label>        {{input type='password' name='live_password'}}      <./div>      <.div class="field">        <.label>{{t 'Live signature'}}<./label>        {{input type='text' name='live_signature'}}      <./div>    {{/if}}    <.button class="ui teal button" type="submit">    {{t 'Save'}}    <./button>   Important tip The action is triggered by the onChange action, hence the variable doesn’t have the value when the template is rendered for the very first time and hence at that instant, none of the fields will be rendered, to avoid that we have used both if and unless condition helpers instead of identical conditional helpers to cleverly…

Continue ReadingUsing ember semantic UI radio buttons to render form elements selectively on Open Event Front End

Making currency name and currency symbol helpers for Open Event Frontend

This blog article will illustrate how to make two helpers which will help us in getting the currency name and symbol from a dictionary, conveniently.The helpers will be used as  a part of currency form on Open Event Front End It also exemplifies the power of ember JS and why is it being used in this project via a counter example in which we try to do things the non ember way and get the required data without using those helpers. So what do we have to begin with ? The sample data which will be fetched from the API: [      {        currency   : 'PLN',        serviceFee : 10.5,        maximumFee : 100.0      },      {        currency   : 'NZD',        serviceFee : 20.0,        maximumFee : 500.0      }      //The list continues ] The dictionary data format: [ { paypal : true, code : 'PLN', symbol : 'zł', name : 'Polish zloty', stripe : true }, { paypal : true, code : 'NZD', symbol : 'NZ$', name : 'New Zealand dollar', stripe : true }, { paypal : false, code : 'INR', symbol : '₹', name : 'Indian rupee', stripe : true } ] // The list continues And our primary goal is to fetch the corresponding name and symbol from the dictionary for a given currency code, easily and efficiently. One might be tempted to get things done the easy way : via {{get (find-by 'code' modal.name currencies) 'name'}} and perhaps, {{get(find-by 'code' modal.name currencies) 'symbol'}} where currencies is the name of the imported array from the dictionary. But this might be hard to follow for a first time reader, and also in case we ever need this functionality to work in a different context, this is clearly not the most feasible choice. Hence helpers come into picture, they can be called anywhere and will have a much simpler syntax Our goal is to make helpers such that the required functionality is achieved with a simpler syntax than the one shown previously.So we will simply generate the helpers’ boiler-plate code via ember CLI $ ember generate helper currency-name $ ember generate helper currency-symbol Next we will import the currency format from the payment dictionary to match it against the name or symbol provided by the user. Now all that remains is finding the correct matching from the dictionary. We import the find function from lodash for that. So, this is how they would look import Ember from 'ember'; import { find } from 'lodash'; import { paymentCurrencies } from 'open-event-frontend/utils/dictionary/payment'; const { Helper } = Ember; export function currencyName(params) { return find(paymentCurrencies, ['code', params[0]]).name; } export default Helper.helper(currencyName);   And for the currency symbol helper import Ember from 'ember'; import { find } from 'lodash'; import { paymentCurrencies } from 'open-event-frontend/utils/dictionary/payment'; const { Helper } = Ember; export function currencySymbol(params) { return find(paymentCurrencies, ['code', params[0]]).symbol; } export default Helper.helper(currencySymbol);   Now all we need to do use them is {{currency-name 'USD'}} and {{currency-symbol 'USD'}} to get the corresponding currency name and symbol. We use find…

Continue ReadingMaking currency name and currency symbol helpers for Open Event Frontend

Creating a notification dropdown in semantic UI for Open Event Frontend

Semantic UI comes packaged with highly responsive components to cater to all front end needs. The area of front-end development is so large, it is never possible to cover all the possible requirements of a developer with pre built components. Currently there is no means to display notifications on the navbar in Open Event Front-end project. In this article we are going to build a notification dropdown from scratch which will be used there to display notifications. So we begin by generating a new component via ember CLI $ ember generate component notification-dropdown This should generate the boiler-plate code for our component, with the template file located at: templates/components/notification-dropdown.hbs and the JS file located at components/notification-dropdown.js  It is assumed that you already have a basic ember app with at least a navbar set up. The notification drop down will be integrated with the navbar as a separate component. This allows us great flexibility in terms of location of the navbar, and also helps us  in not cluttering the code in one file. We will use the popup component of semantic ui as the underlying structure of our dropdown. I have used some dummy data stored in a separate file, you can use any dummy data you wish, either  by directly hardcoding it or importing it from a js file stored somewhere else. It’s preferred if the mock data is called from a js file, because it helps in simulating the server response in a much more genuine way. We will make use of the floating label of semantic UI to display the number of unread notifications. A mail outline icon should make for a good choice to use the primary icon to denote the notifications. Also, the floating label will require additional styling to make it overlap with the icon perfectly. For the header in the dropdown we can give a ‘mark all as read’ button aligned to the right and the ‘notification’ header to the left. Also for best user experience even on small devices, we will make each notification item clickable as a whole instead of individual clickable elements in it. A selection link list of semantic UI should be perfect to display individual notifications as it gives a hovering effect and also, allows us to display a header. Moving onto individual notification items, it will have 3 sub parts A header Description Human friendly notification time For the header we will use the ‘header’ class predefined in semantic UI for list items.We will use ‘content’ class for description which is again a predefined semantic UI class, And finally the time can be displayed via moment-from-now helper of ember to display the time in a human friendly format. <.i class="mail outline icon"> <./i> <.div class="floating ui teal circular mini label">{{notifications.length}}<./div> <.div class="ui wide notification popup bottom left transition ">  <.div class="ui basic inverted horizontal segments">    <.div class="ui basic left aligned segment weight-800">      <.p>{{t 'Notifications'}}<./p>    <./div>    <.div class="ui basic right aligned segment weight-400">      <.a href="#">{{t 'Mark all as Read'}}<./a>…

Continue ReadingCreating a notification dropdown in semantic UI for Open Event Frontend

Efficient use of event card component on Open Event Frontend

Ember JS is a powerful framework when it comes to code reusability. Components are at it’s core and enable the developers to reuse the same code at different places. The event-card component on Open event-front-end is one such component. It is used on various routes across the app thereby illustrating the usefulness. However, in this article we are going to see how components can be made even more efficient by rendering them differently for different situations.Originally the component was used to display events in the card format on the public page. And this was the code : <.div class="ui fluid event card">  <.a class="image" href="{{href-to 'public' event.identifier}}">    {{widgets/safe-image src=(if event.large event.large event.placeholderUrl)}}  <./a>  <.div class="content">    <.a class="header" href="{{href-to 'public' event.identifier}}">      <.span>{{event.name}}<./span>    <./a>    <.div class="meta">      <.span class="date">        {{moment-format event.startTime 'ddd, MMM DD HH:mm A'}}      <./span>    <./div>    <.div class="description">      {{event.shortLocationName}}    <./div>  <./div>  <.div class="extra content small text">    <.span class="right floated">      <.i role="button" class="share alternate link icon" {{action shareEvent event}}><./i>    <./span>    <.span>      {{#each tags as |tag|}}        <.a>{{tag}}<./a>      {{/each}}    <./span>  <./div> <./div> Next we modify it in such a way that it is suitable to be displayed on the explore route as well, and that requires it to be such that is instead of being box-like it should be possible to render it such that it is wide and takes the width of the container it is in. So How do we determine which version should be rendered when. In ember it is really easy to pass on parameters to components while calling them, and they can make use of these paraemeters as they are being rendered. It is best if the name of the parameters is chosen logically, here we want to make it wide for selected routes so we name it : isWide And the code after modification, would be something like this with isWide taken into account. We will just wrap it an extra div which will conditionally add an extra class ‘wide’ if isWide is true. <.div class="{{if isWide 'event wide ui grid row'}}"> <.!-- Previous code --> <./div> //And the corresponding styling for wide class .event.wide {   border-radius: 0 !important;   margin: 0 !important;   .column {     margin: 0;     padding: 0 !important;   }   img {     height: 170px !important;     object-fit: cover;   } .main.content {   height: 130px;   display: block; } } Next What we are going to do is, modify the component to become yieldable. So that they can also be used to display the tickets of a user! `{{yield}}` allows code outside the component to be rendered inside it. Let’s make a change so that, if the event card component is rendered on the my tickets page, then instead of hashtags it should display the ticket details. Which we will conveniently provide to the component externally (via {{yield}} ) Next we need to determine which version of the component should be rendered when? The hasBlock helper enables us to do just that. So the final code should look something just like this ;) The hasBlock helper allows us to differentiate between the…

Continue ReadingEfficient use of event card component on Open Event Frontend

Creating nested routes in Open Event Front-end and Navigating them with Tabs via semantic UI – Ember Integration

Semantic UI is a modern development framework which helps build responsive and aesthetically beautiful layouts. While it is a really powerful framework in itself, it additionally offers seamless integrations with some of the other open source frameworks including ember js. Open Event Front-end is a project of FOSSASIA organisation, which was created with the aim of decoupling the front end and the back end for the open event orga server. It is primarily based on ember JS and uses semantic UI for it’s UI. Here we will be making a nested route /events/ with /events/live/, events/draft, events/past , events/import as it’s subroutes. To get started with it, we simply use the ember CLI to generate the routes $ ember generate route events Then we go on to generate the successive sub routes as follows $ ember generate route events/live $ ember generate route events/past $ ember generate route events/draft $ ember generate route events/import The router.js file should be looking like this now. this.route('events', function() { this.route('live'); this.route('draft'); this.route('past'); this.route('import'); }); This means that our routes and sub routes are in place. Since we used the ember CLI to generate these routes, the template files for them would have generated automatically. Now these routes exist and we need to write the data in the templates of these routes which will get displayed to the end user. Since the routes are nested, the content of the parent route can be made available to all the children routes via the outlet in ember js. Next, we go to the template file of events/ route which is at templates/events.hbs And write the following code to create a menu and use ember integration of semantic UI link-to to link the tabs of the menu with the corresponding correct route. It will take care of selecting the appropriate data for the corresponding route and display it in the correct tab via the outlet <.div class="row"> <.div class="sixteen wide column"> <.div class="ui fluid pointing secondary menu"> {{#link-to 'events.live' class='item'}} {{t 'Live'}} {{/link-to}} {{#link-to 'events.draft' class='item'}} {{t 'Draft'}} {{/link-to}} {{#link-to 'events.past' class='item'}} {{t 'Past'}} {{/link-to}} {{#link-to 'events.import' class='item'}} {{t 'Import'}} {{/link-to}} <./div> <./div> <./div> <.div class="ui segment"> {{outlet}} <./div> So finally, we start filling in the data for each of these routes. Let’s fill some dummy data at templates/events/live.hbs <.div class="row"> <.div class="sixteen wide column"> <.table class="ui tablet stackable very basic table"> <.thead> <.tr> <.th>{{t 'Name'}}<./th> <.th>{{t 'Date'}}<./th> <.th>{{t 'Roles'}}<./th> <.th>{{t 'Sessions'}}<./th> <.th>{{t 'Speakers'}}<./th> <.th>{{t 'Tickets'}}<./th> <.th>{{t 'Public URL'}}<./th> <.th><./th> <./tr> <./thead> <.tbody> <.tr> <.td> <.div class="ui header weight-400"> <.img src="https://placehold.it/200x200" alt="Event logo" class="ui image"> Sample Event <./div> <./td> <.td> March 18, 2016 - 09:30 AM <.br>(to)<.br> March 20, 2016 - 05:30 PM <./td> <.td> <.div class="ui ordered list"> <.div class="item">sample@gmail.com ({{t 'Organizer'}})<./div> <.div class="item">sample2@gmail.com ({{t 'Manager'}})<./div> <./div> <./td> <.td> <.div class="ui list"> <.div class="item">{{t 'Drafts'}}: 0<./div> <.div class="item">{{t 'Submitted'}}: 0<./div> <.div class="item">{{t 'Accepted'}}: 0<./div> <.div class="item">{{t 'Confirmed'}}: 0<./div> <.div class="item">{{t 'Pending'}}: 0<./div> <.div class="item">{{t 'Rejected'}}: 0<./div> <./div> <./td> <.td> 2 <./td> <.td> <.div class="ui bulleted list">…

Continue ReadingCreating nested routes in Open Event Front-end and Navigating them with Tabs via semantic UI – Ember Integration

ember.js – the right choice for the Open Event Front-end

With the development of the API server for the Open Event project we needed to decide which framework to choose for the new Open Event front-end. With the plethora of javascript frameworks available, it got really difficult to decide, which one is actually the right choice. Every month a new framework arrives, and the existing ones keep actively updating themselves often. We decided to go with Ember.js. This article covers the emberJS framework and highlights its advantages over others and  demonstrates its usefulness. EmberJS is an open-source JavaScript application front end framework for creating web applications, and uses Model-View-Controller (MVC) approach. The framework provides universal data binding. It’s focus lies on scalability. Why is Ember JS great? Convention over configuration - It does all the heavy lifting. Ember JS mandates best practices, enforces naming conventions and generates the boilerplate code for the various components and routes itself. This has advantages other than uniformity. It is easier for other developers to join the project and start working right away, instead of spending hours on existing codebase to understand it, as the core structure of all ember apps is similar. To get an ember app started with the basic route, user doesn’t has to do much, ember does all the heavy lifting. ember new my-app ember server After installing this is all it takes to create your app. Ember CLI Similar to Ruby on Rails, ember has a powerful CLI. It can be used to generate boiler plate codes for components, routes, tests and much more. Testing is possible via the CLI as well. ember generate component my-component ember generate route my-route ember test These are some of the examples which show how easy it is to manage the code via the ember CLI. Tests.Tests.Tests. Ember JS makes it incredibly easy to use test-first approach. Integration tests, acceptance tests, and unit tests are in built into the framework. And can be generated from the CLI itself, the documentation on them is well written and it’s really easy to customise them. ember generate acceptance-test my-test This is all it takes to set up the entire boiler plate for the test, which you can customise Excellent documentation and guides Ember JS has one of the best possible documentations available for a framework. The guides are a breeze to follow. It is highly recommended that, if starting out on ember, make the demo app from the official ember Guides. That should be enough to get familiar with ember. Ember Guides is all you need to get started. Ember Data It sports one of the best implemented API data fetching capabilities. Fetching and using data in your app is a breeze. Ember comes with an inbuilt data management library Ember Data. To generate a data model via ember CLI , all you have to do is ember generate model my-model Where is it being used? Ember has a huge community and is being used all around. This article focuses on it’s salient features via the example of…

Continue Readingember.js – the right choice for the Open Event Front-end