Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Events
Videos
Audiobooks
Packt Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds

How-To Tutorials

7018 Articles
article-image-getting-started-impressive-presentations
Packt
25 Mar 2013
8 min read
Save for later

Getting Started with Impressive Presentations

Packt
25 Mar 2013
8 min read
(For more resources related to this topic, see here.) What is impress.js? impress.js is a presentation framework build upon the powerful CSS3 transformations and transitions on modern web browsers. Bartek Szopka is the creator of this amazing framework. According to the creator, the idea came to him while he was playing with CSS transformations. Prezi.com was the source that got him inspired. On w3.org we have the following mentioned about CSS transforms: CSS transforms allows elements styled with CSS to be transformed in twodimensional or three-dimensional space For more information on CSS transformations for those who are interested, visit http://www.w3.org/TR/css3-transforms/. Creating presentations with impress.js is not a difficult task once you get used to the basics of the framework. Slides in impress.js presentations are called steps and they go beyond the conventional presentation style. We can have multiple steps visible at the same time with different dimensions and effects. impress.js step designs are built upon HTML. This means we can create unlimited effects and the only limitation is your imagination. Built-in features impress.js comes with advanced support for most CSS transformations. We can combine these features to provide more advanced visualizations in modern browsers. These features are as follows: Positioning: Elements can be placed in certain areas of the browser window enabling us to move between slides. Scaling: Elements can be scaled up or scaled down to show an overview or a detailed view of elements. Rotating: Elements can be rotated across any given axis. Working on 3D space: Presentations are not limited to 2D space. All the previously mentioned effects can be applied to 3D space with the z axis. Beyond presentations with impress.js This framework was created to build online presentations with awesome effects with the power of CSS and JavaScript. Bartek, who is the creator of this framework, mentions that it has been used for various different purposes expanding the original intention. Here are some of the most common usages of the impress.js framework: Creating presentations Portfolios Sliders Single page websites List of demos containing various types of impress.js presentations can be found at https://github.com/bartaz/impress.js/wiki/Examples-and-demos. Why is it important? You must be wondering why we need to care about such a framework when we have quality presentation programs such as PowerPoint. The most important thing we need to look at is the license for impress.js. Since it is licensed under MIT and GPL we can even change the source codes to customize the framework according to our needs. Also most of the modern browsers support CSS transformations, allowing you to use impress.js, eliminating the platform dependency of presentation programs. Both desktop-based presentations and online presentations are equally good at presenting information to the audience, but online presentations with impress.js provide a slight advantage over desktop-based presentations in terms of usability. The following are some of the drawbacks of desktop program generated presentations, compared to impress.js presentations: Desktop presentations require a presentation creation software or presentation viewer. Therefore, it's difficult to get the same output in different operating systems. Desktop presentations use standard slide-based techniques with a common template, while impress.js presentation slides can be designed in a wide range of ways. Modifications are difficult in desktop-based presentations since it requires presentation creation software. impress.js presentations can be changed instantly by modifying the HTML content with a simple text editor. Creating presentations is not just about filling our slides with a lot of information and animations. It is a creative process that needs to be planned carefully. Best practices will tell us that we should keep the slides as simple as possible with very limited information and, letting presenter do the detailed explanations. Let's see how we can use impress.js to work with some well-known presentation design guidelines. Presentation outline The audience does not have any idea about the things you are going to present prior to the start of the presentation. If your presentation is not up to standard, the audience will wonder how many boring slides are to come and what the contents are going to be. Hence, it's better to provide a preliminary slide with the outline of your presentation. A limited number of slides and their proper placement will allow us to create a perfect outline of the presentation. Steps in impress.js presentations are placed in 3D space and each slide is positioned relatively. Generally, we will not have an idea about how slides are placed when the presentation is on screen. You can zoom in on the steps by using the scaling feature of impress.js. In this way, we can create additional steps containing the overview of the presentation by using scaling features. Using bullet points People prefer to read the most important points articles rather than huge chunks of text . It's wise to put these brief points on the slides and let the details come through your presenting skills. Since impress.js slides are created with HTML, you can easily use bullet points and various types of designs for them using CSS. You can also create each point as a separate step allowing you to use different styles for each point. Animations We cannot keep the audience interested just by scrolling down the presentation slides . Presentations need to be interactive and animations are great for getting the attention of the audience. Generally, we use animations for slide transitions. Even though presentation tools provide advanced animations, it's our responsibility to choose the animations wisely. impress.js provides animation effects for moving, rotating, and scaling step transitions. We have to make sure it is used with purpose. Explaining the life cycle of a product or project is an excellent scenario for using rotation animations. So choose the type of animation that suits your presentation contents and topic. Using themes Most people like to make the design of their presentation as cool as possible. Sometimes they get carried away and choose from the best themes available in the presentation tool. Themes provided by tools are predefined and designed to suit general purposes. Your presentation might be unique and choosing an existing theme can ruin the uniqueness. The best practice is to create your own themes for your presentations. impress.js does not come with built-in themes. Hence there is no other option than to create a new theme from scratch. impress.js steps are different to each other unlike standard presentations, so you have the freedom to create a theme or design for each of the steps just by using some simple HTML and CSS code. Apart from the previous points, we can use typography, images, and videos to create better designs for impress.js presentations. We have covered the background and the importance for impress.js. Now we can move on to creating real presentations using the framework throughout the next few sections. Downloading and configuring impress.js You can obtain a copy of the impress.js library by downloading from the github page at https://github.com/bartaz/impress.js/. The downloaded .zip file contains an example demo and necessary styles in addition to the impress.js file. Extract the .zip file on to your hard drive and load the index.html on the browser to see impress.js in action. The folder structure of the downloaded .zip file is as given in the following screenshot: Configuring impress.js is something you should be able to do quite easily. I'll walk you through the configuration process. First we have to include the impress.js file in the HTML file. It is recommended you load this file as late as possible in your document. Create a basic HTML using the following code: <!doctype html> <html lang="en"> <head> <title>impress.js </title> </head> <body> <script src = "js/impress.js"></script> </body> </html> We have linked the impress.js file just before the closing body tag to make sure it is loaded after all the elements in our document. Then we need to initialize the impress library to make the presentations work. We can place the following code after the impress.js file to initialize any existing presentation in the document which is compatible with the impress library: <script>impress(). init();</script> Since we have done the setup of the impress.js library, we can now create our impressive presentation. Summary In this article we looked at the background of the impress.js framework and how it was created. Then we talked about the importance of impress.js in creating web-based presentations and various types of usage beyond presentations. Finally we obtained a copy of the framework from the official github page and completed the setup. Resources for Article : Further resources on this subject: 3D Animation Techniques with XNA Game Studio 4.0 [Article] Enhancing Your Math Teaching using Moodle 1.9: Part 1 [Article] Your First Page with PHP-Nuke [Article]
Read more
  • 0
  • 0
  • 6153

article-image-creating-first-circos-diagram
Packt
25 Mar 2013
6 min read
Save for later

Creating the first Circos diagram

Packt
25 Mar 2013
6 min read
(For more resources related to this topic, see here.) Getting ready Let's start with the simple task of graphing a relationship between a student's eye and hair color. We can expect some results: brown eyes are more common for students with brown or black hair, and blue eyes are more common amongst blondes. Circos is able to show these relationships with more clarity than a traditional table. We will be using the hair and eye color data available in the book's supplemental materials (HairEyeColor.csv). The data contains the information about hair and eye color of University of Delaware students. Create a folder C:Usersuser_nameCircos BookHairEyeColor, and place the data file into the location. Here, user_name denotes the user name that is used to log in to your computer. The original data is in a size that can be typically stored in a data set. Each line represents a student and their respective hair (black, brown, blonde, or red) and eye (blue, brown, green, or hazel) color. The following table shows the first 10 lines of data: Hair Eye Brown Red Blonde Brown Blonde Brown Black Brown Brown Brown Brown Blue Hazel Blue Blue Brown Brown Hazel   Before we start creating the specific diagram, let's prepare the data into a table. If you wish, you can use Microsoft Excel's PivotTable or Data Pilots of OpenOffice to transform it into a table as follows:   Blue Brown Green Hazel Black Blonde Brown Red 20 94 84 17 68 7 119 26 5 15 29 14 15 11 54 14 In order to use the data for Circos, we need a simpler format. Open a text file and create a table only separated by spaces. We will also change the row and column titles to make it clearer, as follows: X Blue_Eyes Brown_Eyes Green_Eyes Hazel_Eyes Black_Hair 20 68 5 15 Blonde_Hair 94 7 15 11 Brown_Hair 84 119 29 54 Red_Hair 17 26 14 14 The X is simply a place holder. Save this file as HairEyeColorTable.txt as we are ready to use Circos. You can skip the process of making the raw tables. We will be using the HairEyeColorTable.txt file to create the Circos diagram. How to do it… Open the Command Prompt and change the directory to the location of the tableviewer tools in the CircosCircos Toolstoolstableviewerbin, as follows: cd C:Program Files (x86)CircosCircos Toolstoolstableviewerbin Parse the text table (HairEyeColorTable.txt). This will create a new file, HairEyeColorTable-parsed.txt, which will be refined into a Circos diagram as follows: perl parse-table -file "C:Usersuser_nameCircos Book HairEyeColorHairEyeColorTable.txt" > "C:Usersuser_nameCircos BookHairEyeColorHairEyeColorTable-parsed.txt" The parse command consists of a few parts. First, Perl's parse-table instructs Perl to execute the parse program on the HairEyeColorTable.txt file. Second, the > symbol instructs Windows to write the output into another text file called HairEyeColorTable-parsed.txt. Linux Users Linux users can use a simpler, shorter syntax. Steps 2 and 3 can be completed with this command: cat "~/Documents/Circos Book/HairEyeColor/ HairEyeColorTable.txt" | bin/parse-table | bin/ make-conf -dir "~/Documents/user_name/Circos Book/ HairEyeColor/HairEyeColorTable-parsed.txt Create the configuration files from the parsed table using the following command: type "C:Usersuser_nameCircos BookHairEyeColor HairEyeColorTable-parsed.txt" | perl make-conf -dir "C:Users user_nameCircos BookHairEyeColor" This will create 11 new configuration files. These files contain the data and style information which is needed to create the final diagram. This command consists of two parts. We are instructing Windows to pass the text in the HairEyeColorTable-parsed.txt file to the make-conf command. The | (pipe) character separates what we want passed along and the actual command. After the pipe, we are instructing Perl to execute the make-conf command and store the output into a new directory. We need to create a final file, which compiles all the information. This file will also tell Circos how the diagram should appear, such as size, labels, image style, and where the diagram will be saved. We will save the diagram as HairEyeColor.conf. The make-conf command gave us the color.conf file, which associates colors with the final diagram. In addition, the Circos installation provides us with some other basic colors and fonts. The first several lines of code are: <colors> <<include colors.conf>> <<include C:Program Files (x86)Circosetccolors.conf>> </colors> <fonts> <<include C:Program Files (x86)Circosetcfonts.conf>> </fonts> The next segment is the ideogram. These are the parameters that set the details of the image. This first set of lines specifies the spacing, color, and size of the chromosomes: <ideogram> <spacing> default=0.01r break=200u </spacing> thickness = 100p stroke_thickness = 2 stroke_color = black fill = yes fill_color = black radius = 0.7r show_label = yes label_font = condensedbold label_radius = dim(ideogram,radius) + 0.05r label_size = 48 band_stroke_thickness = 2 show_bands = yes fill_bands = yes </ideogram> Next, we will define the image, including where it is stored (this location is mentioned in the following code snippet as dir), the file name, whether we want an SVG or PNG file, size, background color, and any rotation: dir = C:Usersuser_nameCircos BookHairEyeColor file = HairEyeColor svg = yes png = yes 24bit = yes radius = 800p background = white angle_offset = +90 Lastly, we will input the data and define how the links (ribbons) should look: chromosomes_units = 1 karyotype = karyotype.txt <links> z = 0 radius = 1r – 150p bezier_radius = 0.2r <link cell_> ribbon = yes flat = yes show = yes color = black thickness = 2 file = cells.txt </link> show_bands = yes <<include C:Program Files (x86)Circosetchousekeeping.conf>> Save this file as HairEyeColor.conf with the other configuration files. Have a look at the next diagram which explains all this procedure: The make-conf command outputs a few very important files. First, karyotype.txt defines each ideogram band's name, width, and color. Meanwhile, cells.txt is the segdup file containing the actual data. It is very different from our original table, but it dictates the width of each ribbon. Circos links the karyotype and segdup files to create the image. The other configuration files are mostly to set the aesthetics, placement, and size of the diagram. Return to the Command Prompt and execute the following command: cd C:Usersuser_nameCircos BookHairEyeColor perl "C:Program Files (x86)Circosbincircos" –conf HairEyeColor.conf Several lines of text will scroll across the screen. At the conclusion, HairEyeColor.png and HairEyeColor.svg will appear in the folder as shown in the next diagram:
Read more
  • 0
  • 0
  • 3109

article-image-connecting-people
Packt
25 Mar 2013
5 min read
Save for later

Connecting with people

Packt
25 Mar 2013
5 min read
(For more resources related to this topic, see here.) Posting an update To post an Update (the default action) just type your message as follows into the box: That's almost all. Well, okay, we do need to specify who it goes to. In this example-a thank you note to the office staff — I chose the Office group (the drop-down menu shows the groups, click on the little arrow to see them all). Then just click on the Update button and it's done. The published post looks similar to the following screenshot and appears in my feed (as I posted it) but also in the feeds of everyone in the Office group, who enjoy their well-deserved pat on the back. Posting a photo or other graphics An old cliché concerns a picture being worth a thousand words. Actually, due to inflation, a picture is worth about 1500 words these days. There are many reasons to add photos, charts, figures, drawings, and so on to posts. To do so, click on the File tab below the post box (it appears when you click in the post box to start a message). Here you can upload a file (photos are a type of file), select one from those that might already be in your company's Yammer network, or select a page on Yammer. Use the top selection to upload a photo (highlighted in the following screenshot): In this post I want to let everyone in the company know about the new server rack (which we actually recently added). So I type a short message, click on Upload a file from your computer (which opens the standard file selection dialog box provided by your specific operating system). Then I choose and upload a file as you do in any other application. I select the group (over in the left-hand side column) All Company, which by default, makes the post visible to the entire company. The picture is represented by a small thumbnail attached to the post. Clicking on the thumbnail expands it as shown in the following screenshot: Clicking in the post box also reveals as shown in the following screenshot, +Add people to notify (this lets us search for specific people to message) and Search for topics... (this lets us find or create topics like shipping, production, or any other word or term that narrows down what your post is about). We also see the group selection drop-down menu, and the Update button that publishes your post. Commenting and complimenting The third type of post is praising someone. There are two ways of doing this: Originate: Above the posting input box click on Praise Someone (see the following screenshot). Enter their name and what you are praising them for. In addition to creating posts, we want to comment on other peoples' posts similar to the following screenshot. Just click on Reply to open the box for typing. You can also add a photo or other type of file, just like when posting an original message, or search for other people (use the paperclip icon with Add File next to it for that). Yes we LIKE that If we want to just show approval, we click on Like (see the previous section and, yes, it is the same thing as on Facebook). We can also search for other people to add (that is we share Sally's post with them). Learning more There are many options you would like to see that are shown in the following screenshot and described as follows: Add Topics: This option lets us further categorize the post (when your company has thousands upon thousands of posts, you'll really appreciate the topics, which help narrow down the posts to those of a particular interest) View Conversation: This option lets us see all the posts related to this one so we can follow the thread of the conversation Bookmark: This is just that, it lets us easily find this post again Email Me: This sends a copy of the post to your e-mail Delete: This deletes the post (if you have the administrator's permissions to do so)—use it carefully Moving the cursor about a persons name who has created a post reveals information about him or her, plus gives you a link to send them a private message. A green check shows you are following them. If not you can follow them by clicking on the button. It toggles to following so you can unfollow people also. Receiving notifications At the top of the Yammer screen is a useful bar with several items on it as shown in the following screenshot: To the right-hand side of the Yammer logo are two notification icons. The first shows we have one private message and the second (the bell icon) indicates the system has a message for us also. Just click on the icon to see them. Searching he Search box allows us to search the company network for people, topics, and the like. Using the bottom line On the very bottom of the Yammer screen, we find the line pictured as shown in the following screenshot: All the links on the right-hand side in the previous screenshot are general links to Yammer's site. Feel free to explore those and learn more about the Yammer concept as well as keeping up with the latest news and features about Yammer in general. Summary Using all the tasks in this article gives us a head start in using Yammer on a daily basis. A few times posting or doing these actions and you'll quickly be an expert. Resources for Article : Further resources on this subject: Designing the Facebook Clone and Creating Colony using Ruby [Article] Drupal 7 Social Networking: Managing Users and Profiles [Article] Social Bookmarking - MediaWiki [Article]
Read more
  • 0
  • 0
  • 1970

article-image-managing-oracle-business-intelligence
Packt
25 Mar 2013
2 min read
Save for later

Managing Oracle Business Intelligence

Packt
25 Mar 2013
2 min read
(For more resources related to this topic, see here.) Getting ready Oracle Business Intelligence Version 11.1.1.6 is installed on a host other than the OMS host. The agent needs to be up and running on the host where Oracle Business Intelligence is installed. How to do it... To discover the OBIEE 11g target, perform the following steps: Log in to Enterprise Manager Cloud Control. From the Targets tab, select the Middleware option from the drop-down menu. Click on the + Add button on the Middleware home page. Select the Oracle Fusion Middleware/Weblogic Domain option from the drop-down list. Populate the Oracle Business Intelligence Weblogic Domain details on the Add Fusion Middleware Farm: Find Targets screen. Select Administration Server Host of the Oracle Business Intelligence host. Specify the Oracle Business Intelligence domain admin server port, and add a username, a password. Also provide a meaningful Unique Domain Identifier. The default name is left unchanged in this example. Click on Continue. Click on Close. Click on Add Targets to add the discovered components of the Oracle Business Intelligence domain. Click on Close. Verify the Add Fusion Middleware Farm: Results screen. Expand the Show Targets Details tab to view all the components of Oracle Business Intelligence. Click on OK. Click on the Farm01_bifoundation_domain link to monitor and manage all the Oracle Business Intelligence components. How it works... This recipe describes the steps to discover the Oracle Fusion Middleware/WebLogic Domain target. The Fusion Middleware plugin Version 12.1.0.3 is embedded with Cloud Control 12.1.0.2 and is certified to discover components of the Oracle Business Intelligence target, which can be managed and monitored using EM Cloud Control. There's more... Multiple Oracle Business Intelligence instances can be managed and monitored more efficiently using EM Cloud Control 12c. Enterprise Manager displays the performance of the managed targets data in a user-friendly graphical format. Summary This article deals with the steps required to discover the Oracle Fusion Middleware/WebLogic Domain target. Resources for Article : Further resources on this subject: Unveil the Power of Your Business Data with Oracle Discoverer [Article] Oracle Integration and Consolidation Products [Article] Oracle Business Intelligence : Getting Business Information from Data [Article]
Read more
  • 0
  • 0
  • 3202

article-image-managing-network-layout
Packt
22 Mar 2013
15 min read
Save for later

Managing Network Layout

Packt
22 Mar 2013
15 min read
(For more resources related to this topic, see here.) There are two main approaches to working with network structure in Nagios Core: Host parent definitions allow an administrator to define a hierarchy of connectivity to monitored hosts from the "point of view" of the Nagios Core server. An example might be a server with the monitored address in another subnet linked to the Nagios Core server by a router. If the router enters a DOWN state, it triggers Nagios Core's host reachability logic to automatically determine which hosts become inaccessible, and flags these as UNREACHABLE rather than DOWN, allowing refined notification behavior. Host and service dependencies allow the formalization of relationships between hosts or services, usually for the purposes of suppressing unnecessary notifications. An example might be a service that tests a login to a mail service, that itself requires a database service to work properly. If Nagios Core finds that the database service and the login service are both down, a service dependency allows the suppressing of the notification about the login service; the administrator would therefore only be notified about the database service being down, which is more likely to be the actual problem. There is some overlap of functionality here, but the general pattern is that host parent definitions describe the structure of your network from the vantage point of your monitoring server, and host and service dependencies describe the way it functions, independent of the monitoring server. We will define both parent definitions and dependencies in this article, with the primary goal of filtering and improving the notifications that Nagios Core sends in response to failed checks, which can assist greatly in diagnosing problems. We'll also look at another, more subtle benefit of establishing host parent definitions in making the network map of the Nagios Core web interface useful, and once a basic hierarchy is set up, we'll show how to customize the map's appearance (including defining icons for hosts), to make it generally useful as a network weather map. Creating a network host hierarchy In this recipe, we'll learn how to establish a parent-child relationship for two hosts in a very simple network, in order to take advantage of Nagios Core's reachability logic. Changing this configuration is very simple; it involves adding only one directive, and optionally changing some notification options. Getting ready You will need to be running a Nagios Core 3.0 or newer server, and have at least two hosts, one of which is only reachable via the other. The host that allows communications with the other is the parent host. You should be reasonably confident that a loss of connectivity to the parent host necessarily implies that the child host becomes unreachable from the monitoring server. Access to the web interface of Nagios Core would also be useful, as making this change will change the appearance of the network map, discussed in the Using the network map recipe in this article. Our example will use a Nagios Core monitoring server, olympus.naginet, monitoring three hosts: calpe.naginet, a router janus.naginet, another router corsica.naginet, a web server The hosts are connected as shown in the following diagram: Note that the Nagios Core server olympus.naginet is only able to communicate with the corsica.naginet web server if the router calpe.naginet is working correctly. If calpe. naginet were to enter a DOWN state, we would see corsica.naginet enter a DOWN state too: This is a little misleading, as we don't actually know whether corsica.naginet is down. It might be, but with the router in between the hosts not working correctly, Nagios Core has no way of knowing. A more informative and accurate status for the host would be UNREACHABLE; this is what the configuration we're about to add will arrange. How to do it... We can configure a parent-child relationship for our two hosts as follows Change to the objects configuration directory for Nagios Core. The default path is /usr/local/nagios/etc/objects. If you've put the definition for your host in a different file, then move to its directory instead. # cd /usr/local/nagios/etc/objects Edit the file containing the definition for the child host. In our example, the child host is corsica.naginet, the web server. The host definition might look something similar to the following code snippet: define host { use linux-server host_name corsica.naginet alias corsica address 10.128.0.71 } Add a new parents directive to the host's definition, and give it the same value as the host_name directive of the host on which it is dependent for connectivity. In our example, that host is calpe.naginet. define host { use linux-server host_name corsica.naginet alias corsica address 10.128.0.71 parents calpe.naginet } Validate the configuration and restart the Nagios Core server: # /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg# /etc/init.d/nagios restart With this done, if the parent host enters a DOWN state and the child host can't be contacted, then the child host will enter an UNREACHABLE state rather than also being flagged as DOWN: The child host's contacts will also receive UNREACHABLE notification s instead of DOWN notifications for the child host, provided the u flag is included in notification_options for the host, and host_notification_options for the contacts. How it works... This is a simple application of Nagios Core's reachability logic. When the check to calpe. naginet fails for the first time, Nagios Core notes that it is a parent host for one child host, corsica.naginet. If during checks for the child host it finds it cannot communicate with it, it flags an UNREACHABLE state instead of the DOWN state, firing a different notification event. The primary advantages to this are twofold: The DOWN notification is only sent for the nearest problem parent host. All other hosts beyond that host fire UNREACHABLE notifications. This means that Nagios Core's reachability logic automatically determines the point of failure from its perspective, which can be very handy in diagnosing which host is actually experiencing a problem. If the host is a parent to a large number of other hosts, the configuration can be arranged not to send urgent notifications for UNREACHABLE hosts. There may not be much point sending a hundred pager or e-mail messages to an administrator when a very central router goes down; they know there are problems with the downstream hosts, so all we would be doing is distracting them with useless information. With a little planning and some knowledge of the network, all we need to do is add a few parents directives to host definitions to build a simple network structure, and Nagios Core will behave much more intelligently as a result. This is one of the easiest ways to refine the notification behavior of Nagios Core; it can't be recommended enough! There's more... Note that a child host can itself be a parent to other hosts in turn, allowing a nesting network structure. Perhaps in another situation, we might find that the corsica.naginet server is two routers away from the monitoring server: In this case, not only is corsica.naginet the child host of calpe.naginet, but calpe. naginet is itself the child host of janus.naginet. We could specify this relationship in exactly the same way: define host { use linux-router host_name calpe.naginet alias calpe address 10.128.0.129 parents janus.naginet } It's also possible to set multiple parents for a host, if there are two possible paths to the same machine: define host { use linux-server host_name corsica.naginet alias corsica address 10.128.0.71 parents calpe.naginet,janus.naginet } With this configuration, corsica.naginet would only be deemed UNREACHABLE if both of its parent hosts were down. This kind of configuration is useful to account for redundant paths in a network; use cases could include spanning tree technologies, or dynamic routing failover After you've set up a good basic structure for your network using the parents directive, definitely check out the Using the network map recipe in this article to get some automatic visual feedback about your network's structure as generated from your new configuration. See also The Using the network map and Establishing a host dependency recipes in this article Using the network map In this recipe, we'll examine our network hierarchy in the network map (or status map) in the Nagios Core web interface. The network map takes the form of a generated graphic showing the hierarchy of hosts and their current states. You can learn how to establish such a hierarchy in the recipe Creating a network host hierarchy in this article. The network map allows filtering to show specific hosts, and clicking on hosts to navigate through larger networks. Getting ready You will need to be running a Nagios Core 3.0 or newer server, and have access to its web interface. You will also need permission to view the states of hosts, preferably all hosts. You can arrange this by adding your username in the authorized_for_all_hosts directive, normally in /usr/local/nagios/etc/cgi.cfg; for example, for the user tom, we might configure the directive to read as follows: authorized_for_all_hosts=nagiosadmin,tom By default, the nagiosadmin user should have all the necessary permissions to view the complete map. The network map is not particularly useful without at least a few hosts configured and arranged in a hierarchy, so if you have not set any parents directives for your hosts, then you may wish to read the Creating a network host hierarchy recipe in this article first, and arrange your monitored hosts as it explains. How to do it... We can inspect the network map for our newly configured host hierarchy like so: Log in to the Nagios Core web interface. Click on the Map item in the menu on the left: You should be presented with a generated graphic showing all the hosts in your network that your user has permissions to view: Hover over any host with the mouse to see a panel breaking down the host's current state: By default, the network map is centered around the Nagios Process icon. Try clicking on one of your hosts to recenter the map; in this example, it's recentered on calpe.naginet: How it works... The network map is automatically generated from your host configuration. By default, it arranges the hosts in sectors, radiating outward from the central Nagios Process icon, using lines to show dependencies, and adjusting background colors to green for UP states, and red for DOWN or UNREACHABLE states. This map is generated via the GD2 library, written by Thomas Boutell. It takes the form of a linked image map. This means that you can simply right-click the image to save it while the network is in a particular state for later reference, and also that individual nodes can be clicked to recenter the map around the nominated host. This is particularly useful for networks with a large number of hosts and very many levels of parent/child host relationships. There's more... Note that the form in the panel in the top-right allows customizing the appearance of the map directly: Layout Method: This allows you to select the algorithm used to arrange and draw the hosts. It's worth trying each of these to see which you prefer for your particular network layout. Scaling factor: Change the value here to reduce or increase the size of the map image; values between 0.0 and 1.0 will reduce the image's size, and values above 1.0 will increase it. Drawing Layers: If your hosts are organized into hostgroups, you can filter the map to only display hosts belonging to particular groups. Layer mode: If you selected any host groups in the Drawing Layers option, this allows you to select whether you want to include hosts in those groups in the map, or exclude them from it. Suppress popups: If you find the yellow information popups that appear when hovering over hosts annoying, then you can turn them off by selecting this checkbox. After selecting or changing any one of these options, you will need to click on Update to apply them. The appearance of the status map can be configured well beyond this by changing directives in the Nagios Core configuration file, and adding some directives to your hosts; take a look at the recipes under the See also section of this recipe for some examples of how this is done. See also The Customizing appearance of the network map , Choosing icons for hosts, Specifying coordinates for a host on the network map, and Using the network map as an overlay recipes in this article Choosing icons for hosts In this recipe, we'll learn how to select graphics for hosts, to appear in various parts of the Nagios Core web interface. This is done by adding directives to a host to specify the paths to appropriate images to represent it. Adding these definitions has no effect on Nagios Core's monitoring behavior; they are mostly cosmetic changes, although it's useful to see at a glance whether a particular node is a server or a workstation, particularly on the network map. Getting ready You will need to be running a Nagios Core 3.0 or newer server, and have access to its web interface. You must also be able to edit the configuration files for the server. It's a good idea to check that you actually have the required images installed. The default set of icons is included in /usr/local/nagios/share/images/logos. Don't confuse this with its parent directory, images, which contains images used as part of the Nagios Core web interface itself. In the logos directory, you should find a number of images in various formats. In this example, we're interested in the router and rack-server icons: $ ls /usr/local/nagios/share/images/logos/{router,rack-server}.*/usr/local/nagios/share/images/logos/rack-server.gd2/usr/local/nagios/share/images/logos/rack-server.gif/usr/local/nagios/share/images/logos/router.gd2/usr/local/nagios/share/images/logos/router.gif To get the full benefit of the icons, you'll likely want to be familiar with using the network map, and have access to view it with the appropriate hosts in your own Nagios Core instance. The network map is introduced in the Using the network map recipe in this article. How to do it... We can define images to be used in displaying our host as follows: Change to the objects configuration directory for Nagios Core. The default path is /usr/local/nagios/etc/objects. If you've put the definition for your host in a different file, then move to its directory instead. # cd /usr/local/nagios/etc/objects Add three new directives to each of the hosts to which you want to apply the icons. In this example, the rack-server icon is assigned to corsica.naginet, and the router icon to both calpe.naginet and corsica.naginet: define host { use linux-server host_name corsica.naginet alias corsica address 10.128.0.71 icon_image rack-server.gif icon_image_alt Rack Server statusmap_image rack-server.gd2 } define host { use linux-router host_name janus.naginet alias janus address 10.128.0.128 icon_image router.gif icon_image_alt Router statusmap_image router.gd2 } define host { use linux-router host_name calpe.naginet alias calpe address 10.128.0.129 icon_image router.gif icon_image_alt Router statusmap_image router.gd2 } Validate the configuration and restart the Nagios Core server: # /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg# /etc/init.d/nagios restart With this done, a visit to the status map should display the appropriate hosts with icons rather than question marks: The Hosts list should also include a scaled-down version of the image: How it works... When a host list, service list, or network status map is generated, it checks for the presence of icon_image or statusmap_image values for each host object, reads the appropriate image if defined, and includes that as part of its processing. The network status map defaults to displaying only a question mark in the absence of a value for the statusmap_image directive. Note that for the statusmap_image directive, we chose the .gd2 version of the icon rather than the .gif version. This is for performance reasons; the status map is generated with the GD2 library, which deals more efficiently with its native .gd2 format. The icon_image_alt directive defines the value for the alt attribute when the image is displaying in an <img> HTML tag. Most web browsers will show the contents of this tag after briefly hovering over the icon. Nagios Core 3.0 allows you to put these directives in a separate hostextinfo object, but this object type is officially deprecated as of Nagios Core 4.0, so it's recommended to avoid it. There's more If you have a number of hosts that need to share the same image, it's a good practice to inherit from a common host template with the appropriate directives set. For our example, we might define a template as follows: define host { name router-icon icon_image router.gif icon_image_alt Router statusmap_image router.gd2 register 0 } We could then apply the image settings directly to both our routers simply by inheriting from that template, by adding it to the use directive: define host { use linux-router,router-icon host_name janus.naginet alias janus address 10.128.0.128 } define host { use linux-router,router-icon host_name calpe.naginet alias calpe address 10.128.0.129 } If you don't like the included icon set, there are many icon sets available online on the Nagios Exchange site at http://exchange.nagios.org/. If you want, you could even make your own, out of pictures of your physical hardware, saved in standard PNG or GD2 format. See also The Using the network map and Specifying coordinates for a host on the network map recipes in this article
Read more
  • 0
  • 0
  • 5014

article-image-lets-chat
Packt
22 Mar 2013
7 min read
Save for later

Let's Chat

Packt
22 Mar 2013
7 min read
(For more resources related to this topic, see here.) Creating the application We will create our application, which will be called awesome-chat, by executing the following commands in the Node.js command line: $ express awesome-chat $ cd awesome-chat $ npm install This will create our application and install the express application dependencies. Open the package.json file and change the name to awesome-chat, as shown in the following code snippet: { "name": "awesome-chat", "version": "0.0.1", "private": true, "scripts": { "start": "node app" }, "dependencies": { "express": "3.0.0rc2express": "3.x", "jade": "*" } } Designing the chat room Let's modify the view to make it look like a chat room. We will need an area to display the messages, a text input for the user to enter the message, and a button to send the message. We will add some aesthetic elements, such as a header, banner, and footer. When we are done, our chat room user interface should look like the one shown in the following screenshot: Awesome chat UI Let's start editing layout.jade by adding a header and footer to it: doctype 5 html block head title= title link(rel='stylesheet', href='/stylesheets/style.css') body header#banner h1 Awesome Chat block content footer Hope you enjoy your stay here The first change we make is to add the block keyword before head. This makes head a block, to which we can append content from the extending pages. The other change is the addition of a new header and footer. Note that we are using the header and footer tags from HTML5. This code also introduces us to a new jade syntax. When we write header#banner , it will generate headers with banner as the id value. The generated HTML code will be as follows: <!DOCTYPE html> <html> <head> <title>{TITLE}</title> <link rel="stylesheet" href="/stylesheets/style.css" /> </head> <body> <header id="banner"> <h1>Awesome Chat</h1> </header> {CONTENT} <footer> Hope you enjoy your stay here </footer> </body> </html> Next, we will edit index.jade to add the message area, message input, and the Send button: extends layout block content section#chatroom div#messages input#message(type='text', placeholder='Enter your message here') input#send(type='button', value='Send') Let's run and see what our awesome-chat application looks like. Execute the application using npm and open http://localhost:3000/ in the browser: npm start Hey, all the elements are there, but it doesn't look right! That's correct; to improve the look and feel of the application, we need to edit the stylesheet, which is located at public/stylesheets/style.css. We can edit it according to our taste. Here is one that works just fine for me: html { height: 100%; } body { font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; margin: 0px; padding: 0px; height: -moz-calc(100% - 20px); height: -webkit-calc(100% - 20px); height: calc(100% - 20px); } section#chatroom { height: -moz-calc(100% - 80px); height: -webkit-calc(100% - 80px); height: calc(100% - 80px); background-color: #EFFFEC; } div#messages { height: -moz-calc(100% - 35px); height: -webkit-calc(100% - 35px); height: calc(100% - 35px); padding: 10px; -moz-box-sizing:border-box; -webkit-box-sizing:border-box; box-sizing:border-box; } input#message { width: -moz-calc(100% - 80px); width: -webkit-calc(100% - 80px); width: calc(100% - 80px); } input#send { width: 74px; } header{ background-color:#4192C1; text-align: right; margin-top: 15px; } header h1{ padding: 5px; padding-right: 15px; color: #FFFFFF; margin: 0px; } footer{ padding: 6px; background-color:#4192C1; color: #FFFFFF; bottom: 0; position: absolute; width: 100%; margin: 0px; margin-bottom: 10px; -moz-box-sizing:border-box; -webkit-box-sizing:border-box; box-sizing:border-box; } a { color: #00B7FF; } After saving this CSS and refreshing the page, here is what the chat room looks like: The awesome chat room Bringing in jQuery jQuery is almost ubiquitous when it comes to JavaScript libraries, and we will use it in our application too. To add jQuery to our application, let's download the latest release from http://www.jquery.com/ and save it to public/javascript/jquery.min.js . Then, we add the script in layout.jade to pull in jQuery to our application's pages: script(type='text/javascript', src = '/javascripts/jquery.min.js') Socket.IO Ever since the onset of web applications, developers have worked towards different ways of getting duplex communication between the server and the browser. Be it using Java, Flash, Comet, or many other workarounds, all aim to do the same. But for the first time, there is a specification to build a full-duplex communication system by using HTML5 WebSockets. WebSocket is a revolutionary, new communication feature in the HTML5 specification that defines a full-duplex communication channel operating over the Web through a single socket. Although the WebSockets RFC is published, it is not, and will never be, available on older browsers that are still in use. Socket.io is an abstraction layer for WebSockets, with Flash, XHR, JSONP, and HTMLFile fallbacks. Socket.io provides an easy server and client library for making real-time, streaming updates between a web server and a browser client. Socket.io is a node module available through the npm, and we will add it to our package dependencies. The current release of socket.io is 0.9.10. To add this to our dependencies, add the following line to the dependencies object in package.json: "socket.io": "0.9.10" And install it using the npm: $ npm install This will bring socket.io in the node_modules folder. Now let's see how we will use it. Handling events Since the socket.io framework has components for both the server and the client, we will use these components to code our communication on both the sides. Events emitted on a socket on one side will be handled by the corresponding event handler on the other side. Socket.io is built so that both the sides can send messages or attach handlers to process the incoming messages. Let's begin by understanding how the messages will flow. It is important to remember that "messages" here are not the actual messages sent and received by users of the chat system, but the messages used for communication by the client and the server. There will be two types of messages, as follows: The system messages: These messages will be sent by our chat system to the client, like when the user is connected, when others connect, or when users disconnect. Let's identify it with serverMessage. The user messages: These messages will be sent by the client to the server and will actually carry the user's message content in the payload. We will probably want to differentiate between the messages we send and the messages other users send. So let's call them myMessage and userMessage respectively. When a user connects for the first time, the server will send a welcome message to the user as a serverMessage message. When a user types in a message and presses the Send button, we will send a userMessage message from the browser to the server. On receiving the user message, the server will broadcast this message to all the other users. It will also send back the same message as myMessage to the user who originally sent the message. On receiving any message from the server, the browser will display the contents of the message in the message area.
Read more
  • 0
  • 0
  • 2676
Unlock access to the largest independent learning library in Tech for FREE!
Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
Renews at €18.99/month. Cancel anytime
article-image-doing-it-forms
Packt
21 Mar 2013
8 min read
Save for later

Doing it with Forms

Packt
21 Mar 2013
8 min read
(For more resources related to this topic, see here.) The form component In order to collect and handle data Ext comes with the Ext.form.Panel class. This class extends from the panel so we can place the form in any other container. We also have all the functionality the panel offers, such as adding a title and using layouts. If we look at the wireframes, we can see that we need to have the functionality of creating, editing, and deleting clients from our database: We are going to work on this form. As seen in the previous screenshot the form contains a title, a toolbar with some buttons, and a few fields. One important thing to keep in mind when working with Ext JS is that we should create our components isolated from the other components as much as we can. This way we can reuse them in other modules or even extend them to add new functionality. First we need to extend from the Form class, so let's create a JavaScript file with the following code: Ext.define('MyApp.view.clients.Form',{ extend : 'Ext.form.Panel', alias : 'widget.clientform', title : 'Client form', initComponent : function(){ var me = this; me.callParent(); } }); We need to create the file in the following path: MyApp/view/clients/Form.js The previous code doesn't do much, it's only extending from the form panel, defining an alias and a title. The initComponent method is empty, but we're going to create some components for it. Now let's create an HTML file, where we can test our new class. We need to import the Ext JS library, our JS file, where our new class is, and wait for the DOM ready event to create an instance of our class: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Texfield</title> <!-- Importing the Ext JS library --> <script type="text/javascript" src = "../ext-4.1.1a-gpl/ext-all-dev. js"></script> <linkrel="stylesheet" href="../ext-4.1.1a-gpl/resources/css/ext-all. css" /> <script type="text/javascript" src = "MyApp/view/clients/Form.js"></ script> <script type="text/javascript"> Ext.onReady(function(){ Ext.create('MyApp.view.clients.Form',{ width : 300, height : 200, renderTo: Ext.getBody() }); }); </script> <style type="text/css"> body{padding:10px;} </style> </head> <body> </body> </html> We are creating an instance of the Client form as usual. We have set the width, height, and the place where the form is going to be rendered, in this case the body of our document. As a result we have our form created as shown in the following screenshot: So far we have an empty form. We can add any of the available components and widgets, let's start with the textfield property: Ext.define('MyApp.view.clients.Form',{ extend : 'Ext.form.Panel', alias : 'widget.clientform', title : 'Client form', bodyPadding : 5, defaultType : 'textfield', //Step 1 initComponent : function(){ var me = this; me.items = me.buildItems(); //Step 2 me.callParent(); }, buildItems : function(){ //Step 3 return [{ fieldLabel : 'Name', name : 'name' },{ fieldLabel : 'Contact', name : 'contact' }]; } }); The steps are explained as follows: Step 1: We have defined the default type of component we are going to use. This way we don't have to define the xtype property every time we want to create textfield. Step 2: We use the items property to add components to our form. We are calling a function that should return an array of components. Step 3: We are defining two textfields. First we set the value of the label for each textfield and then we set name. It's important to use name if we want to send or retrieve data to our server. Setting the name property will allow us to set and retrieve data to our fields in an easy way. Using a function to define the items array is a great way to write our code for readability. Also if we would like to extend this class, we can override this method and add more components to our form in the subclass. With the previous lines of code we have added two textfields to our form as shown in the following screenshot: Now let's add the Address field to our form using a textarea property. In order to do that we need to override the default xtype property as follows: Ext.define('MyApp.view.clients.Form',{ //... buildItems : function(){ return [ //... ,{ xtype : 'textarea', fieldLabel : 'Address', name : 'address' } ]; } }); If we want to define new components we can override the xtype property with the component we need. In this case we are using a textarea xtype, but we can use any of the available components. The last field in our wireframe is a textfield to collect the phone number. We already defined the default xtype as textfield so we only need to define the name and the label of our new textfield as follows: Ext.define('MyApp.view.clients.Form',{ //... buildItems : function(){ return [ //... ,{ fieldLabel : 'Phone', name : 'phone' } ]; } }); As a result we have all the required fields in our form. Now if we refresh our browser, we should see something like the following screenshot: We have our form ready, but if we see our wireframe we can realize that something is missing. We need to add three buttons to the top of the panel. We already know how to create toolbars and buttons; the following code should be familiar for us: Ext.define('MyApp.view.clients.Form',{ //... initComponent : function(){ var me = this; me.items = me.buildItems(); me.dockedItems = me.buildToolbars(); //Step 1 me.callParent(); }, buildItems : function(){ //... }, buildToolbars : function(){ //Step 2 return [{ xtype : 'toolbar', docked : 'top', items : [{ text : 'New', iconCls : 'new-icon' },{ text : 'Save', iconCls : 'save-icon' },{ text : 'Delete', iconCls : 'delete-icon' }] }]; } }); In the previous code, we are defining the dockedItems property; we are using the same pattern of defining a function that returns the array of items in the first step. In the second step we define a function that returns an array of components to be docked. In this case we are only returning a toolbar docked to the top; this toolbar contains three buttons. The first button is for a new client, the second one is to save the current client, and the third button is to delete the current client in the form. We need to use CSS classes to add an icon to the buttons. The previous code is using three different classes so we need to create them: <style type="text/css"> .new-icon{background:transparent url(images/page_add.png) 0 0 norepeat !important;} .save-icon{background:transparent url(images/disk.png) 0 0 no-repeat !important;} .delete-icon{background:transparent url(images/delete.png) 0 0 norepeat !important;} </style> Once we have defined our CSS classes let's refresh our browser and see our latest changes in action: We have finished our wireframe, but the form is not doing anything yet. For now let's just move forward and see what other components we have available. Anatomy of the fields Ext JS provides many components to give the user a great experience when using their applications. The following fields are components we can use in a form or outside of the form, for example, we can add a textfield or a combobox to a toolbar, where we place some filters or search options. Every input field extends from the Ext.Component class; this means that every field has its own lifecycle, events, and also can be placed on any container. There's also a class called Ext.form.field.Base that defines common properties, methods, and events across all form fields. This base class also extends from the Ext. form.Labelable and Ext.form.field.Field classes (using mixins). The Labelable class gives the field the ability to display a label and errors in every subclass such as textfields, combos, and so on. The Field class gives the fields the ability to manage their value, because it adds a few important methods, such as the getValue and setValue methods to set and retrieve the current value of the field; also this class introduces an important concept, the raw value. A great example of the raw value is when we pull data from our server and we get a date value in string format, the raw value is in plain text, but the value of the date field should be in a native Date object so that we can work easily with dates and time. We can always use the raw value, but it's recommended to use the value instead, which in this example is a Date object.
Read more
  • 0
  • 0
  • 1656

Packt
21 Mar 2013
13 min read
Save for later

Learn Cinder Basics – Now

Packt
21 Mar 2013
13 min read
(For more resources related to this topic, see here.) What is creative coding This is a really short introduction about what creative coding is, and I'm sure that it is possible to find out much more about this topic on the Internet. Nevertheless, I will try to explain how it looks from my perspective. Creative coding is a relatively new term for a field that combines coding and design. The central part of this term might be the "coding" one—to become a creative coder, you need to know how to write code and some other things about programming in general. Another part—the "creative" one—contains design and all the other things that can be combined with coding. Being skilled in coding and design at the same time lets you explain your ideas as working prototypes for interface designs, art installations, phone applications, and other fields. It can save time and effort that you would give in explaining your ideas to someone else so that he/she could help you. The creative coding approach may not work so well in large projects, unless there are more than one creative codes involved. A lot of new tools that make programming more accessible have emerged during the last few years. All of them are easy to use, but usually the less complicated a tool is, the less powerful it is, and vice versa. A few words about Cinder So we are up to some Cinder coding! Cinder is one of the most professional and powerful creative coding frameworks that you can get for free on the Internet. It can help you if you are creating some really complicated interactive real-time audio-visual piece, because it uses one of the most popular and powerful low-level programming languages out there—C++—and relies on minimum third-party code libraries. The creators of Cinder also try to use all the newest C++ language features, even those that are not standardized yet (but soon will be) by using the so called Boost libraries. This book is not intended as an A-to-Z guide about Cinder nor the C++ programming language, nor areas of mathematics involved. This is a short introduction for us who have been working with similar frameworks or tools and know some programming already. As Cinder relies on C++, the more we know about it the better. Knowledge of ActionScript, Java, or even JavaScript will help you understand what is going on here. Introducing the 3D space To use Cinder with 3D we need to understand a bit about 3D computer graphics. First thing that we need to know is that 3D graphics are created in a three-dimensional space that exists somewhere in the computer and is transformed into a two-dimensional image that can be displayed on our computer screens afterwards. Usually there is a projection (frustrum) that has different properties which are similar to the properties of cameras we have in the real world. Frustrum takes care of rendering all the 3D objects that are visible in frustrum. It is responsible for creating the 2D image that we see on the screen. As you can see in the preceding figure, all objects inside the frustrum are being rendered on the screen. Objects outside the view frustrum are being ignored. OpenGL (that is being used for drawing in Cinder) relies on the so called rendering pipeline to map the 3D coordinates of the objects to the 2D screen coordinates. Three kind of matrices are used for this process: the model, view, and projection matrices. The model matrix maps the 3D object's local coordinates to the world (or global) space, the view matrix maps it to the camera space, and finally the projection matrix takes care of the mapping to the 2D screen space. Older versions of OpenGL combine the model and view matrices into one—the modelview matrix. The coordinate system in Cinder starts from the top-left corner of the screen. Any object placed there has the coordinates 0, 0, 0 (these are values of x, y, and z respectively). The x axis extends to the right, y to the bottom, but z extends towards the viewer (us), as shown in the following figure: Drawing in 3D Let's try to draw something by taking into account that there is a third dimension. Create another project by using TinderBox and name it Basic3D. Open the project file ( xcode/Basic3D.xcodeproj on Mac or vc10\Basic3D.sln on Windows). Open Basic3DApp.cpp in the editor and navigate to the draw() method implementation. Just after the gl::clear() method add the following line to draw a cube: gl::drawCube( Vec3f(0,0,0), Vec3f(100,100,100) ); The first parameter defines the position of the center of the cube, the second defines its size. Note that we use the Vec3f() variables to de fine position and size within three (x, y and z) dimensions. Compile and run the project. This will draw a solid cube at the top-left corner of the screen. We are able to see just one quarter of it because the center of the cube is the reference point. Let's move it to the center of the screen by transforming the previous line as follows: gl::drawCube( Vec3f(getWindowWidth()/2,getWindowHeight()/2,0), Vec3f(100,100,100) ); Now we are positioning the cube in the middle of the screen no matter what the window's width or height is, because we pass half of the window's width (getWindowWidth()/2 ) and half of the window's height ( getWindowHeight()/2) as values for the x and y coordinates of the cube's location. Compile and run the project to see the result. Play around with the size parameters to understand the logic behind it. We may want to rotate the cube a bit. There is a built-in rotate() function that we can use. One of the things that we have to remember, though, is that we have to use it before drawing the object. So add the following line before gl::drawCube(): gl::rotate( Vec3f(0,1,0) ); Compile and run the project. You should see a strange rotation animation around the y axis. The problem here is that the rotate() function rotates the whole 3D world of our application including the object in it and it does so by taking into account the scene coordinates. As the center of the 3D world (the place where all axes cross and are zero) is in the top-left corner, all rotation is happening around this point. To change that we have to use the translate() function. It is used to move the scene (or canvas) before we rotate() or drawCube(). To make our cube rotate around the center of the screen, we have to perform the following steps: Use the translate() function to translate the 3D world to the center of the screen. Use the rotate() function to rotate the 3D world. Draw the object (drawCube()). Use the translate()function to translate the scene back. We have to use the translate() function to translate the scene back to the location, because each time we call translate() values are added instead of being replaced. In code it should look similar to the following: gl::translate( Vec3f(getWindowWidth()/2,getWindowHeight()/2,0) ); gl::rotate( Vec3f::yAxis()*1 ); gl::drawCube( Vec3f::zero(), Vec3f(100,100,100) ); gl::translate( Vec3f(-getWindowWidth()/2,-getWindowHeight()/2,0) ); So now we get a smooth rotation of the cube around the y axis. The rotation angle around y axis is increased in each frame by 1 degree as we pass the Vec3f::yAxis()*1 value to the rotate() function. Experiment with the rotation values to understand this a bit more. What if we want the cube to be in a constant rotated position? We have to remember that the rotate() function works similar to the translate function. It adds values to the rotation of the scene instead of replacing them. Instead of rotating the object back, we will use the pushMatrices() and popMatrices() functions. Rotation and translation are transformations. Every time you call translate() or rotate() , you are modifying the modelview matrix. If something is done, it is sometimes not so easy to undo it. Every time you transform something, changes are being made based on all previous transformations in the current state. So what is this state? Each state contains a copy of the current transformation matrices. By calling pushModelView() we enter a fresh state by making a copy of the current modelview matrix and storing it into the stack. We will make some crazy transformations now without worrying about how we will undo them. To go back, we call popModelView() that pops (or deletes) the current modelview matrix from the stack, and returns us to the state with the previous modelview matrix. So let's try this out by adding the following code after the gl::clear() call: gl::pushModelView(); gl::translate( Vec3f(getWindowWidth()/2,getWindowHeight()/2,0) ); gl::rotate( Vec3f(35,20,0) ); gl::drawCube( Vec3f::zero(), Vec3f(100,100,100) ); gl::popModelView(); Compile and run our program now, you should see something similar to the following screenshot: As we can see, before doing anything, we create a copy of the current state with pushModelView(). Then we do the same as before, translate our scene to the middle of the screen, rotate it (this time 35 degrees around x axis and 20 degrees around y axis), and finally draw the cube! To reset the stage to the state it was before, we have to use just one line of code, popModelView(). Using built-in eases Now, say we want to make use of the easing algorithms that we saw in the EaseGallery sample. To do that, we have to change the code by following certain steps. To use the easing functions, we have to include the Easing.h header file:#include "cinder/Easing.h" First we are going to add two more variables, startPostition and circleTimeBase: Vec2f startPosition[CIRCLE_COUNT]; Vec2f currentPosition[CIRCLE_COUNT]; Vec2f targetPosition[CIRCLE_COUNT]; float circleRadius[CIRCLE_COUNT]; float circleTimeBase[CIRCLE_COUNT]; Then, in the setup() method implementation, we have to change the currentPosition parts to startPosition and add an initial value to the circleTimeBase array members: startPosition[i].x = Rand::randFloat(0, getWindowWidth()); startPosition[i].y = Rand::randFloat(0, getWindowHeight()); circleTimeBase[i] = 0; Next, we have to change the update() method so that it can be used along with the easing functions. They are based on time and they return a floating point value between 0 and 1 that defines the playhead position on an abstract 0 to 1 timeline: void BasicAnimationApp::update() { Vec2f difference; for (int i=0; i<CIRCLE_COUNT; i++) { difference = targetPosition[i] - startPosition[i]; currentPosition[i] = easeOutExpo( getElapsedSeconds()-circleTimeBase[i]) * difference + startPosition[i]; if ( currentPosition[i].distance(targetPosition[i]) < 1.0f ) { targetPosition[i].x = Rand::randFloat(0, getWindowWidth()); targetPosition[i].y = Rand::randFloat(0, getWindowHeight()); startPosition[i] = currentPosition[i]; circleTimeBase[i] = getElapsedSeconds(); } } } The highlighted parts in the preceding code snippet are those that have been changed. The most important part of it is the currentPosition[i] calculation part. We take the distance between the start and end points of the timeline and multiply it with the position floating point number that is being returned by our easing function, which in this case is easeOutExpo() . Again, it returns a floating point variable between 0 and 1 that represents the position on an abstract 0 to 1 timeline. If we multiply any number with, say, 0.33f, we get one-third of that number, 0.5f, we get one-half of that number, and so on. So, we add this distance to the circle's starting position and we get it's current position! Compile and run our application now. You should see something as follows: Almost like a snow storm! We will add a small modification to the code though. I will add a TWEEN_SPEED definition at the top of the code and multiply the time parameter passed to the ease function with it, so we can control the speed of the circles: #define TWEEN_SPEED 0.2 Change the following line in the update() method implementation: currentPosition[i] = easeOutExpo( (getElapsedSeconds()-circleTimeBase[i])*TWEEN_SPEED) * difference + startPosition[i]; I did this because the default time base for each tween is 1 second. That means that each transition is happening exactly for 1 second and that's a bit too fast for our current situation. We want it to be slower, so we multiply the time we pass to the easing function with a floating point number that is less than 1.0f and greater than 0.0f. By doing that we ensure that the time is scaled down and instead of 1 second we get 5 seconds for our transition. So try to compile and run this, and see for yourself! Here is the full source code of our circle-creation: #include "cinder/app/AppBasic.h" #include "cinder/gl/gl.h" #include "cinder/Rand.h" #include "cinder/Easing.h" #define CIRCLE_COUNT 100 #define TWEEN_SPEED 0.2 using namespace ci; using namespace ci::app; using namespace std; class BasicAnimationApp : public AppBasic { public: void setup(); void update(); void draw(); void prepareSettings( Settings *settings ); Vec2f startPosition[CIRCLE_COUNT]; Vec2f currentPosition[CIRCLE_COUNT]; Vec2f targetPosition[CIRCLE_COUNT]; float circleRadius[CIRCLE_COUNT]; float circleTimeBase[CIRCLE_COUNT]; }; void BasicAnimationApp::prepareSettings( Settings *settings ) { settings->setWindowSize(800,600); settings->setFrameRate(60); } void BasicAnimationApp::setup() { for(int i=0; i<CIRCLE_COUNT; i++) { currentPosition[i].x=Rand::randFloat(0, getWindowWidth()); currentPosition[i].y=Rand::randFloat(0, getWindowHeight()); targetPosition[i].x=Rand::randFloat(0, getWindowWidth()); targetPosition[i].y=Rand::randFloat(0, getWindowHeight()); circleRadius[i] = Rand::randFloat(1, 10); startPosition[i].x = Rand::randFloat(0, getWindowWidth()); startPosition[i].y = Rand::randFloat(0, getWindowHeight()); circleTimeBase[i] = 0; } } void BasicAnimationApp::update() { Vec2f difference; for (int i=0; i<CIRCLE_COUNT; i++) { difference = targetPosition[i] - startPosition[i]; currentPosition[i] = easeOutExpo( (getElapsedSeconds()-circleTimeBase[i]) * TWEEN_SPEED) * difference + startPosition[i]; if ( currentPosition[i].distance( targetPosition[i]) < 1.0f ) { targetPosition[i].x = Rand::randFloat(0, getWindowWidth()); targetPosition[i].y = Rand::randFloat(0, getWindowHeight()); startPosition[i] = currentPosition[i]; circleTimeBase[i] = getElapsedSeconds(); } } } void BasicAnimationApp::draw() { gl::clear( Color( 0, 0, 0 ) ); for (int i=0; i<CIRCLE_COUNT; i++) { gl::drawSolidCircle( currentPosition[i], circleRadius[i] ); } } CINDER_APP_BASIC( BasicAnimationApp, RendererGl ) Experiment with the properties and try to change the eases. Not all of them will work with this example, but at least you will understand how to use them to create smooth animations with Cinder. Summary This article explains what is Cinder, introduces the 3D space, how to draw in 3D, and also explains in short about using built-in eases. Resources for Article : Further resources on this subject: 3D Vector Drawing and Text with Papervision3D: Part 1 [Article] Sage: 3D Data Plotting [Article] Building your First Application with Papervision3D: Part 2 [Article]
Read more
  • 0
  • 0
  • 3263

article-image-implementation-sass
Packt
21 Mar 2013
8 min read
Save for later

Implementation of SASS

Packt
21 Mar 2013
8 min read
(For more resources related to this topic, see here.) Downloading and installing SASS We're going to kick off the recipes by downloading and setting up SASS ready for use — this will get your system ready to compile SASS files as you create them. Getting ready For this recipe you will need a few things — you will need your choice of normal text editor; I normally use TextPad, which is available on a commercial license at http://www.textpad.com, although please feel free to use whichever editor you prefer. You will also need a copy of RubyInstaller for Windows, which you can download from http://www.rubyinstaller.org/downloads ; at the time of writing, the latest version is 1.9.3. If you are a Mac OS X user, you will already have Ruby installed as part of the operating system; Linux users can download and install it through their distribution's package manager. How to do it... Let's begin by running rubyinstaller-1.9.3-p286.exe , and clicking on Run when prompted. At the Select Setup Language window prompt, select your preferred language — the default is English. At the License Agreement window, select I accept the license then click on Next. At the Installation Destination and Optional Tasks window, select Add Ruby executables to your PATH, and Associate .rb and .rbw files with this Ruby installation: Click on Install. Ruby will now install, you will see a progress window displayed on the screen while the software is being installed. A dialog window will appear when this is completed. Click on Finish to close the window. The next stage is to install SASS. For this, you need to bring up a command prompt, then type gem install sass and press Enter. Ruby will now go ahead and install SASS – you will see an update similar to the following screenshot: You may find this takes a short while, with little apparent change on screen; there is no need to worry, as it will still be downloading and installing SASS. Now that SASS is installed, we can go ahead and start creating SASS files. Open up your text editor, add the following lines, and save it as example1.scss in a folder called c:sass: $blue: #3bbfce; $margin: 16px; .content-navigation { border-color: $blue; color: darken($blue, 9%); } .border { padding: $margin / 2; margin: $margin / 2; border-color: $blue; } We now need to activate the compiler. If you don't already have a session open, bring up a command prompt, and enter the following: sass --watch c:sassexample1.scss:c:sassexample1.css If you get a "permission denied" error when running sass --watch, then make sure you are running the command prompt as an administrator. This activates the SASS compiler which will then automatically generate a CSS file when any change is made to the SCSS file: As soon as you save the file, the SASS compiler will pick up the change, and update the appropriate CSS file accordingly: If you look in the c:sass folderexample1.css file that has been generated, you will see the resulting CSS, which you can then attach to your project: .content-navigation { border-color: #3bbfce; color: #2ca2af; } .border { padding: 8px; margin: 8px; border-color: #3bbfce; } How it works... In this recipe, we've installed Ruby and SASS, and looked at how to run the SASS --watch command to set the SASS compiler to automatically compile CSS files when you create SCSS files. In this instance, we created a basic SCSS file, which SASS has parsed; it works out where variable "placeholders" have been used, and replaces them with the appropriate value that has been specified at the start of the file. Any variables included in the SASS file that are not subsequently used, are automatically dropped by SASS. When using Ruby 1.9, SASS is able to automatically determine which character encoding it should use, and will handle this in the same way as CSS (which is UTF-8 by default or a more local encoding for some users). You can change this if needed; simply add @charset "ENCODING-NAME"; at the beginning of the stylesheet, where ENCODING-NAME is the name of a format that can be converted to Unicode. While the creation of CSS files using this method is simple, it is a manual process that has to be run outside of your text editor. In the next recipe, we'll take a look at how you can add support so you can compile code from within your text editor, using Sublime Text 2 as your example editor. Viewing SASS in a browser When you have compiled your SASS files into valid CSS, an important step is to then test to see that it works. If you start seeing unexpected results, you will want to troubleshoot the CSS code. The trouble is, most browsers don't include support to trace back a SASS-compiled style to its original SASS code; we can fix that (at least for Firefox), by using FireSASS. Getting ready For this exercise, you will need a copy of Firefox, with Firebug installed. You can get the latter from http://www.getfirebug.com. How to do it... Let's get FireSASS installed. To do this, you need to browse to https://addons.mozilla.org/en-US/firefox/addon/firesass-for-firebug/, then click on the Add to Firefox button: Firefox will prompt you to allow it to install. Click on Allow, then on Install Now on the window that appears. You will need to restart Firefox for FireSASS to complete its installation. To test it, we need to create a SASS file with some example code, and use it within a HTML test page. Go ahead and add the following to a copy of the template, and save it as example2.html, within the c:sass folder we created earlier: <body> <form action=""> Name: <input type="text" class="input" /> Password: <input type="password" class="input" /> <input type="submit" value="This is a button" id="submitfrm" /> </form> </body> Add the following to a new SCSS file within Sublime Text 2. Save this as example2.scss; you will also need to link this into the <head> section of your code: $color-button: #d24444; #submitfrm { color: #fff; background: $color-button; border: 1px solid $color-button - #222; padding: 5px 12px; } Activate the SASS compiler from the command prompt, using the following command: sass --watch c:sassexample2.scss:c:sassexample2.css --debug-info If all is well, you should see the following screenshot when you view the file in your browser: How it works... FireSASS works by replacing the line number of the CSS style in use, with that of the line number from the original SCSS file: It relies on the --watch function being activated with --debug-info enabled. Using the previous example, we can see from the screenshot that the border color calculation of border: 1px solid $color-button - #222 returned a color of #B02222, which is a slightly darker shade of red than the main button itself. The beauty of this is that no matter whatever color you decide to use, the calculation will automatically return the right shade of color for the border. Not convinced? Change the $color-button variable to something completely different. I've chosen #3bbfce. Now recompile the SASS file in Sublime Text 2 and the result is a nice shade of blue: Okay, so we've only changed the color for one button in this example – it doesn't matter if you make a change for one button or many; using this code means you only need to change one variable to update any button that uses the same variable in your code. There's more... If you look into the folder where you are storing your SASS files, you may notice the presence of a .sass-cache folder, inside which there will be one or more .scssc files as shown in the following screenshot: These are cache files, which live in the same folder as your source files by default. They are created by SASS when initially compiling SCSS files. This dramatically speeds up the compilation process, particularly when you have a large number of files to compile. It works even better if styles for a project have been separated into one of these files, which SASS can then compile into one large master file. Summary Thus in this article, we saw that the Role Tailored approach provides a single point of access into the system for each user through their assigned Role Center. The user's Role Center acts as their home page. We saw how Role Center focuses on the tasks needed to support its users' jobs throughout the day. Resources for Article : Further resources on this subject: Inheritance in Python [Article] Managing the IT Portfolio using Troux Enterprise Architecture [Article] Data Migration Scenarios in SAP Business ONE Application- part 1 [Article]
Read more
  • 0
  • 0
  • 9663

Packt
20 Mar 2013
8 min read
Save for later

Quick start – Firebug window overview and inspecting

Packt
20 Mar 2013
8 min read
(For more resources related to this topic, see here.) Console panel The console panel offers a JavaScript command line. The JavaScript command line is a very powerful weapon of Firebug. This feature provides you with the power of executing arbitrary JavaScript expressions and commands on the fly at the command line without even reloading the document. You can validate and execute any JavaScript on the command line before integrating it on your web page. When something goes wrong, Firebug will quickly let you know the details and information about: JavaScript errors and warnings CSS errors XML errors External errors Chrome errors and messages Network errors Strict warnings (performance penalty) Stack trace with errors XHR (xmlHttpRequest) info HTML panel The HTML panel displays the generated HTML of the currently opened web page. It allows you to edit HTML on the fly and play with your HTML DOM (document object model) in Firefox. It differs from the normal source code view, because it also displays all manipulations on the DOM tree. On the right-hand side it shows the CSS styles defined for the currently selected tag, the computed styles for it, layout information, and the DOM variables assigned to it under different tabs. CSS panel When you want to alter CSS rules, the CSS panel is the right place for this. It allows the user to tweak the CSS stylesheet in his/her taste. You can use this panel for viewing/editing CSS stylesheets on the fly and view the results live on the current document. This tab is mostly used by CSS developers to tweak the pixels, position, look and feel, or area of an HTML element. This tab is also useful for web developers when they want to view those elements whose CSS property display is set to none. Furthermore it offers an exclusive editing mode, in which you can edit the content of the CSS files directly via a text area. Script panel The Script panel is the next gem that Firebug provides for us. It allows you to debug JavaScript code on the browser. The script panel integrates a powerful debugging tool based on features such as different kinds of breakpoints, step-by-step execution of scripts, a display for the variable stack, watch expressions, and more. Things you can perform under the Script panel A few tasks that you can perform under the Script panel and play with JavaScript are as follows: View the list of JavaScript files that are loaded with your document Debug the JavaScript code Insert and remove breakpoints Insert and remove conditional breakpoints View the stack trace View list of breakpoints Add new Watch expressions Keep an eye on the watches for viewing the values of variables Debug an Ajax call DOM panel HTML elements are also known as DOM elements. Document Object Model (DOM) represents the hierarchy of the HTML elements and functions. You can traverse in any direction within the DOM using JavaScript. The DOM elements have parent, child, and sibling relationships between them therefore for objects and arrays it offers an expandable tree view. Clicking on them (objects and arrays) limits the display of the DOM tree to the context of these objects and shows the current element path as a breadcrumb list on the DOM panel's toolbar. The DOM panel in Firebug shows: DOM properties DOM functions DOM constants User-defined properties User-defined functions Inline event handlers Enumerable properties Own properties Net panel The Net panel allows you to monitor the network traffic initiated by your web page. It shows all collected and computed information in a tabular form to the user. Each row in the table represents one request or response round trip made by the web page. You can quickly measure the performance of your web page by analyzing the following information: Time taken to load the page The size of each file The loading time of each file The number of requests the browser sends to load the page The Net panel also provides the facility to filter the type of request or response that you want to focus on. You can choose filters to view only HTML, CSS, JS, Image, Flash, Media, and even XHR (Ajax) requests. Cookies panel The Cookies panel allows you to view, manage, and debug cookies within your browser via Firebug. Within the context of the current domain, this panel displays a list of all cookies associated with the current web page. Each entry in the list shows the basic information about a cookie (Name, Value, Domain, Path, Expires, and so on). Inspecting page components Sometimes, something in your page doesn't quite look correct and you want to know why; you want to understand how a particular section of the page has been constructed. Firebug's Inspect functionality allows you to do that in the fastest possible manner using minimal clicks or mouse strokes. As you move around the web page, Firebug creates visual frames around various page components/sections and shows the HTML and CSS behind the page section. In fact, this is one of the most frequently used features while tweaking the look and feel of your web application. Inspecting page elements and doing tweaks (editing HTML attributes, CSS rules, and so on) are real time savers during the fine-tuning of a web application's look and feel. In this section, you will learn how to perform one of the core tasks of Firebug; inspecting and editing HTML. The following steps will help you perform this task. You can activate Firebug by pressing the F12 key or by clicking on the (bug) icon on the top-right side of the browser's toolbar. Similarly, you can close or deactivate Firebug by pressing the F12 key or by clicking on the (bug) again.   Step 1 – open Firebug To start inspection of your web page, you first need to activate Firebug. Go to your web application's page in the browser Press the F12 key or click on the (bug) icon on the top-right side of the Firefox browser's toolbar Step 2 – activate inspection tool In this step, you activate the inspection tool and search for the block/component/HTML element in your web page using the mouse: Click on the Inspect button on the Firebug console toolbar (the inspect button is like a mouse arrow pointer on the toolbar of Firebug), as shown in the following screenshot: Move your mouse cursor over the page component/section that you want to inspect Step 3 – selecting the element While moving the mouse pointer, a visual frame is created around the element and the HTML source of the element is shown highlighted in the Firebug window. Now, after activating the inspection tool, select the block/component/HTML element to inspect. Click on the page component/section to select the element in the HTML panel. Quick inspect You can even inspect an element with minimal fuss by right-clicking on the element in the Firefox window and selecting the Inspect Element with Firebug option from the context menu. This allows you to inspect an element without first activating the Firebug window. In this way you can inspect an element with minimal mouse-clicks when the Firebug window is not already activated. Editing page components Firefox and most other browsers have a feature for viewing the source of the HTML document sent by the server. Firebug's HTML panel shows you what the HTML currently looks like. In addition to the HTML panel, there are three tabs on the right which let you view and modify properties on an individual element, including the CSS rules that are being applied to the element, the layout of the element in the document, and its DOM properties. Firebug's HTML panel has more advanced features than the default View Source of Firefox. It shows the HTML DOM in a hierarchical structure or tree view with a highlight color. It allows you to expand or collapse the HTML DOM to navigate and provides easy visualization of the HTML page. It is a viewer as well as an editor, and it allows you to edit/delete the HTML elements or attributes on the fly and the changes are immediately applied to the page being currently viewed and rendered by the browser. In order to edit the HTML source on a web page, do the following steps: Open Firebug. Click on the HTML tab. This will show the source of the document. Simply click on the Edit button under the HTML panel. On clicking this button, the HTML panel turns into an editable text area. You can now edit the HTML and see it taking effect instantly as shown in the following screenshot: Summary Firebug is armed with lot of weapons to deal with UI and JavaScript bugs. You have the JavaScript command line, the Console panel, HTML panel, CSS panel, Script panel, DOM panel, Net panel, and Cookies panel to tackle a variety of issues. Inspection is the most common task that you will perform almost every time you find yourself surrounded by hair pulling client side issues. Editing and viewing changes on the fly (without making changes on the server side code) is the specialty of Firebug. Resources for Article : Further resources on this subject: Configuring the ChildBrowser plugin [Article] Tips and Tricks for Working with jQuery and WordPress [Article] Skinner's Toolkit for Plone 3 Theming (Part 1) [Article]
Read more
  • 0
  • 0
  • 1284
article-image-creating-animated-gauge-css3
Packt
20 Mar 2013
15 min read
Save for later

Creating an Animated Gauge with CSS3

Packt
20 Mar 2013
15 min read
(For more resources related to this topic, see here.) A basic gauge structure Let's begin with a new project; as usual we need to create an index.html file. This time the markup involved is so small and compact that we can add it right now: <!doctype html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <title>Go Go Gauges</title> <link rel="stylesheet" type="text/css" href="css/application.css"> </head> <body> <div data-gauge data-min="0" data-max="100" data-percent="50"> <div data-arrow></div> </div> </body> </html> The gauge widget is identified by the data-gauge attribute and defined with three other custom data attributes; namely, data-min, data-max, and data-percent, which indicate the respective minimum and maximum value of the range and the current arrow position expressed in percentage value. Within the element marked with the data-gauge attribute, we have defined a div tag that will become the arrow of the gauge. To start with the styling phase, we first need to equip ourselves with a framework that is easy to use and can give us the opportunity to generate CSS code. We decide to go for SASS so we first need to install Ruby (http://www.ruby-lang.org/en/downloads/) and then enter the following from a command-line terminal: gem install sass You would probably need to execute the following command if you are working in Unix/Linux environments: sudo gem install sass   Installing Compass For this project we'll also use Compass, a SASS extension able to add some interesting features to our SASS stylesheet. To install Compass, we have to just enter gem install compass (or sudo gem install compass) in a terminal window. After the installation procedure is over, we have to create a small config.rb file in the root folder of our project using the following code: # Require any additional compass plugins here. # Set this to the root of your project when deployed: http_path = YOUR-HTTP-PROJECT-PATH css_dir = "css" sass_dir = "scss" images_dir = "img" javascripts_dir = "js" # You can select your preferred output style here (can be overridden via the command line): # output_style = :expanded or :nested or :compact or :compressed # To enable relative paths to assets via compass helper functions. Uncomment: relative_assets = true # To disable debugging comments that display the original location of your selectors. Uncomment: # line_comments = false preferred_syntax = :sass The config.rb file helps Compass to understand the location of the various assets of the project; let's have a look at these options in detail: http_path: This must be set to the HTTP URL related to the project's root folder css_dir: This contains the relative path to the folder where the generated CSS files should be saved sass_dir: This contains the relative path to the folder that contains our .scss files images_dir: This contains the relative path to the folder that holds all the images of the project javascripts_dir: This is similar to images_dir, but for JavaScript files There are other options available; we can decide whether the output CSS should be compressed or not, or we can ask Compass to use relative paths instead of absolute ones. For a complete list of all the options available, see the documentation at http://compass-style.org/help/tutorials/configuration-reference/. Next, we can create the folder structure we just described, providing our project with the css, img, js, and scss folders. Lastly, we can create an empty scss/application.scss file and start discovering the beauty of Compass. CSS reset and vendor prefixes We can ask Compass to regenerate the CSS file after each update to its SCSS counterpart. To do so, we need to execute the following command from the root of our project using a terminal: compass watch . Compass provides an alternative to the Yahoo! reset stylesheet we used in our previous project. To include this stylesheet, all we have to do is add a SASS include directive to our application.scss file: @import "compass/reset"; If we check css/application.css, the following is the result (trimmed): /* line 17, ../../../../.rvm/gems/ruby-1.9.3-p194/gems/compass- 0.12.2/frameworks/compass/stylesheets/compass/reset/_utilities.scss */ html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video { margin: 0; padding: 0; border: 0; font: inherit; font-size: 100%; vertical-align: baseline; } /* line 22, ../../../../.rvm/gems/ruby-1.9.3-p194/gems/compass- 0.12.2/frameworks/compass/stylesheets/compass/reset/_utilities.scss */ html { line-height: 1; } ... Notice also how the generated CSS keeps a reference to the original SCSS; this comes in handy when it's a matter of debugging some unexpected behaviors in our page. The next @import directive will take care of the CSS3 experimental vendor prefixes. By adding @import "compass/css3" on top of the application.scss file, we ask Compass to provide us with a lot of powerful methods for adding experimental prefixes automatically; for example, the following snippet: .round { @include border-radius(4px); } Is compiled into the following: .round { -moz-border-radius: 4px; -webkit-border-radius: 4px; -o-border-radius: 4px; -ms-border-radius: 4px; -khtml-border-radius: 4px; border-radius: 4px; } Equipped with this new knowledge, we can now start deploying the project. Using rem For this project we want to introduce rem, a measurement unit that is almost equivalent to em, but is always relative to the root element of the page. So, basically we can define a font size on the html element and then all the sizes will be related to it: html{ font-size: 20px; } Now, 1rem corresponds to 20px; the problem of this measurement is that some browsers, such as Internet Explorer version 8 or less, don't actually support it. To find a way around this problem, we can use the following two different fallback measurement units: em: The good news is that em, if perfectly tuned, works exactly as rem; the bad news is that this measurement unit is relative to the element's font-size property and is not relative to html. So, if we decide to pursue this method, we then have to take extra care every time we deal with font-size. px: We can use a fixed unit pixel size. The downside of this choice is that in older browsers, we're complicating the ability to dynamically change the proportions of our widget. In this project, we will use pixels as our unit of measurement. The reason we have decided this is because one of the rem benefits is that we can change the size of the gauge easily by changing the font-size property with media queries. This is only possible where media queries and rem are supported. Now, we have to find a way to address most of the duplication that would emerge from having to insert every statement containing a space measurement unit twice (rem and px). We can easily solve this problem by creating a SASS mixin within our application.scss file as follows (for more info on SASS mixins, we can refer to the specifications page at http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#mixins): @mixin px_and_rem($property, $value, $mux){ #{$property}: 0px + ($value * $mux); #{$property}: 0rem + $value; } So the next time instead of writing the following: #my_style{ width: 10rem; } We can instead write: #my_style{ @include px_and_rem(width, 10, 20); } In addition to that, we can also save the multiplier coefficient between px and rem in a variable and use it in every call to this function and within the html declaration; let's also add this to application.scss: $multiplier: 20px; html{ font-size: $multiplier; } Of course, there are still some cases in which the @mixin directive that we just created doesn't work, and in such situations we'll have to handle this duality manually. Basic structure of a gauge Now we're ready to develop at least the basic structure of our gauge, which includes the rounded borders and the minimum and maximum range labels. The following code is what we need to add to application.scss: div[data-gauge]{ position: absolute; /* width, height and rounded corners */ @include px_and_rem(width, 10, $multiplier); @include px_and_rem(height, 5, $multiplier); @include px_and_rem(border-top-left-radius, 5, $multiplier); @include px_and_rem(border-top-right-radius, 5, $multiplier); /* centering */ @include px_and_rem(margin-top, -2.5, $multiplier); @include px_and_rem(margin-left, -5, $multiplier); top: 50%; left: 50%; /* inset shadows, both in px and rem */ box-shadow: 0 0 #{0.1 * $multiplier} rgba(99,99,99,0.8), 0 0 #{0.1 * $multiplier} rgba(99,99,99,0.8) inset; box-shadow: 0 0 0.1rem rgba(99,99,99,0.8), 0 0 0.1rem rgba(99,99,99,0.8) inset; /* border, font size, family and color */ border: #{0.05 * $multiplier} solid rgb(99,99,99); border: 0.05rem solid rgb(99,99,99); color: rgb(33,33,33); @include px_and_rem(font-size, 0.7, $multiplier); font-family: verdana, arial, sans-serif; /* min label */ &:before{ content: attr(data-min); position: absolute; @include px_and_rem(bottom, 0.2, $multiplier); @include px_and_rem(left, 0.4, $multiplier); } /* max label */ &:after{ content: attr(data-max); position: absolute; @include px_and_rem(bottom, 0.2, $multiplier); @include px_and_rem(right, 0.4, $multiplier); } } With box-shadow and border, we can't use the px_and_rem mixin, so we duplicated these properties using px first and then rem. The following screenshot shows the result: Gauge tick marks How to handle tick marks? One method would be by using images, but another interesting alternative is to benefit from multiple background support and create those tick marks out of gradients. For example, to create a vertical mark, we can use the following within the div[data-gauge] selector: linear-gradient(0deg, transparent 46%, rgba(99, 99, 99, 0.5) 47%, rgba(99, 99, 99, 0.5) 53%, transparent 54%) Basically, we define a very small gradient between transparent and another color in order to obtain the tick mark. That's the first step, but we're yet to deal with the fact that each tick mark must be defined with a different angle. We can solve this problem by introducing a SASS function that takes the number of tick marks to print and iterates up to that number while also adjusting the angles of each mark. Of course, we also have to take care of experimental vendor prefixes, but we can count on Compass for that. The following is the function. We can create a new file called scss/_gauge.scss for this and other gauge-related functions; the leading underscore is to tell SASS to not create a .css file out of this .scss file, because it will be included in a separate file. @function gauge-tick-marks($n, $rest){ $linear: null; @for $i from 1 through $n { $p: -90deg + 180 / ($n+1) * $i; $linear: append($linear, linear-gradient( $p, transparent 46%, rgba (99,99,99,0.5) 47%, rgba(99,99,99,0.5) 53%, transparent 54%), comma); } @return append($linear, $rest); } We start with an empty string adding the result of calling the linear-gradient Compass function, which handles experimental vendor prefixes, with an angle that varies based on the current tick mark index. To test this function out, we first need to include _gauge.scss in application.scss: @import "gauge.scss"; Next, we can insert the function call within the div[data-gauge] selector in application.scss, specifying the number of tick marks required: @include background(gauge-tick-marks(11,null)); The background function is also provided by Compass and it is just another mechanism to deal with experimental prefixes. Unfortunately, if we reload the projects the results are far from expected: Although we can see a total of 11 stripes, they are of the wrong sizes and in the wrong position. To resolve this, we will create some functions to set the correct values for background-size and background-position. Dealing with background size and position Let's start with background-size, the easiest. Since we want each of the tick marks to be exactly 1rem in size, we can proceed by creating a function that prints 1rem 1rem as many times as the number of the passed parameter; so let's add the following code to _gauge.scss: @function gauge-tick-marks-size($n, $rest){ $sizes: null; @for $i from 1 through $n { $sizes: append($sizes, 1rem 1rem, comma); } @return append($sizes, $rest, comma); } We already noticed the append function; an interesting thing to know about it is that the last parameter of this function lets us decide if some letter must be used to concatenate the strings being created. One of the available options is comma, which perfectly suits our needs. Now, we can add a call to this function within the div[data-gauge] selector: background-size: gauge-tick-marks-size(11, null); And the following is the result: Now the tick marks are of the right size, but they are displayed one above the other and are repeated all across the element. To avoid this behavior, we can simply add background-repeat: no-repeat just below the previous instruction: background-repeat: no-repeat; On the other hand, to handle the position of the tick marks we need another SASS function; this time it's a little more complex and involves a bit of trigonometry. Each gradient must be placed in the function of its angle—x is the cosine of that angle and y the sine. The sin and cos functions are provided by Compass, we need just to handle the shift, because they are referred to the center of the circle whereas our css property's origin is in the upper-left corner: @function gauge-tick-marks-position($n, $rest){ $positions: null; @for $i from 1 through $n { $angle: 0deg + 180 / ($n+1) * $i; $px: 100% * ( cos($angle) / 2 + 0.5 ); $py: 100% * (1 - sin($angle)); $positions: append($positions, $px $py, comma); } @return append($positions, $rest, comma); } Now we can go ahead and add a new line inside the div[data-gauge] selector: background-position: gauge-tick-marks-position(11, null); And here's the much-awaited result: The next step is to create a @mixin directive to hold these three functions together, so we can add the following to _gauge.scss: @mixin gauge-background($ticks, $rest_gradient, $rest_size, $rest_position) { @include background-image( gauge-tick-marks($ticks, $rest_gradient) ); background-size: gauge-tick-marks-size($ticks, $rest_size); background-position: gauge-tick-marks-position($ticks, $rest_position); background-repeat: no-repeat; } And replace what we placed inside div[data-gauge] in this article with a single invocation: @include gauge-background(11, null, null, null ); We've also left three additional parameters to define extra values for background, background-size, and background-position, so we can, for example, easily add a gradient background: @include gauge-background(11, radial-gradient(50% 100%, circle, rgb(255,255,255), rgb(230,230,230)), cover, center center ); And following is the screenshot: Creating the arrow To create an arrow we can start by defining the circular element in the center of the gauge that holds the arrow. This is easy and doesn't introduce anything really new; here's the code that needs to be nested within the div[data-gauge] selector: div[data-arrow]{ position: absolute; @include px_and_rem(width, 2, $multiplier); @include px_and_rem(height, 2, $multiplier); @include px_and_rem(border-radius, 5, $multiplier); @include px_and_rem(bottom, -1, $multiplier); left: 50%; @include px_and_rem(margin-left, -1, $multiplier); box-sizing: border-box; border: #{0.05 * $multiplier} solid rgb(99,99,99); border: 0.05rem solid rgb(99,99,99); background: #fcfcfc; } The arrow itself is a more serious business; the basic idea is to use a linear gradient that adds a color only to half the element starting from its diagonal. Then we can rotate the element in order to move the pointed end at its center. The following is the code that needs to be placed within div[data-arrow]: &:before{ position: absolute; display: block; content: ''; @include px_and_rem(width, 4, $multiplier); @include px_and_rem(height, 0.5, $multiplier); @include px_and_rem(bottom, 0.65, $multiplier); @include px_and_rem(left, -3, $multiplier); background-image: linear-gradient(83.11deg, transparent, transparent 49%, orange 51%, orange); background-image: -webkit-linear-gradient(83.11deg, transparent, transparent 49%, orange 51%, orange); background-image: -moz-linear-gradient(83.11deg, transparent, transparent 49%, orange 51%, orange); background-image: -o-linear-gradient(83.11deg, transparent, transparent 49%, orange 51%, orange); @include apply-origin(100%, 100%); @include transform2d( rotate(-3.45deg)); box-shadow: 0px #{-0.05 * $multiplier} 0 rgba(0,0,0,0.2); box-shadow: 0px -0.05rem 0 rgba(0,0,0,0.2); @include px_and_rem(border-top-right-radius, 0.25, $multiplier); @include px_and_rem(border-bottom-right-radius, 0.35, $multiplier); } To better understand the trick behind this implementation, we can temporarily add border: 1px solid red within the &:before selector to the result and zoom a bit: Moving the arrow Now we want to position the arrow to the correct angle depending on the data-percent attribute value. To do so we have to take advantage of the power of SASS. In theory the CSS3 specification would allow us to valorize some properties using values taken from attributes, but in practice this is only possible while dealing with the content property. So what we're going to do is create a @for loop from 0 to 100 and print in each iteration a selector that matches a defined value of the data-percent attribute. Then we'll set a different rotate() property for each of the CSS rules. The following is the code; this time it must be placed within the div[data-gauge] selector: @for $i from 0 through 100 { $v: $i; @if $i < 10 { $v: '0' + $i; } &[data-percent='#{$v}'] > div[data-arrow]{ @include transform2d(rotate(#{180deg * $i/100})); } } If you are too scared about the amount of CSS generated, then you can decide to adjust the increment of the gauge, for example, to 10: @for $i from 0 through 10 { &[data-percent='#{$i*10}'] > div[data-arrow]{ @include transform2d(rotate(#{180deg * $i/10})); } } And the following is the result:    
Read more
  • 0
  • 0
  • 4224

article-image-responsive-techniques
Packt
20 Mar 2013
9 min read
Save for later

Responsive techniques

Packt
20 Mar 2013
9 min read
(For more resources related to this topic, see here.) Media queries Media queries are an important part of responsive layouts. They are part of CSS to make it possible to add styles specific to a certain media. Media queries can target the output type, screen size, as well as the device orientation, and even the density of the display. But let's have a look at a simple example before we get lost in theory: #header { background-repeat: no-repeat; background-image: url(logo.png); } @media print { #header { display: none; } } The highlighted line in the preceding code snippet makes sure that all the nested styles are only used if the CSS file is used on a printer. To be a bit more precise, it will hide the element with the ID header once you print the document. The same could be achieved by creating two different files and including them with a code as follows: <link rel="stylesheet" media="all" href="normal.css" /> <link rel="stylesheet" media="print" href="print.css" /> It's not always clear whether you want to create a separate CSS file or not. Using too many CSS files might slow down the loading process a bit, but having one big file might make it a bit messier to handle it. Having a separate print CSS is something you'll see rather often while screen resolution dependent queries are usually in the main CSS file. Here's another example where we use the screen width to break a two columns layout into a single column layout if the screen gets smaller. The following screenshot shows you the layout on an average desktop computer as well as on a tablet: The HTML code we need for our example looks as follows: <div class="box">1</div> <div class="box">2</div> The CSS including the media queries could be as follows: .box { width: 46%; padding: 2%; float: left; } @media all and (max-width: 1023px) { .box { width: 96%; float: none; } } By default, each box has a width of 46 percent and a padding of 2 percent on each side, adding up to a total width of 50 percent. If you look at the highlighted line, you can see a media query relevant to all media types but with a restriction to a maximum width of 1023 pixels. This means that if you view the page on a device with a screen width less than 1023 pixels, the nested CSS styles will be used. In the preceding example, we're overriding the default width of 46 percent with 96 percent. In combination with the 2 percent padding that is still there, we're going to stretch the box to the width of the screen. Checking the maximum width can achieve a lot already, but there are different queries as well. Here are a few queries that could be useful: The following query matches the iPad but only if the orientation is landscape. You could also check the portrait mode by using orientation: portrait. @media screen and (device-width: 768px) and (device-height: 1024px) and (orientation: landscape) If you want to display content specific for a high-resolution screen such as a retina display, use this: @media all and (-webkit-min-device-pixel-ratio: 2) Instead of checking the maximum width, you can also do it the other way round and check the minimum width. The following query could be used to use styles only used in a normal-sized screen: @media screen and (min-width: 1224px) There are a lot more variables you can check in a media query. You can find a nicely arranged list of queries including a testing application on the following site: http://cssmediaqueries.com/ Try to get an overview of what's possible; but don't worry, you'll hardly ever need more than four media queries. How to scale pictures We've seen how you can check the device type in a few different ways, and also used this to change a two-column layout into a single-column layout. This allows you to rearrange the layout elements; but what happens to pictures if the container, in which the picture is located, changes size? If you look at the following screen, you can see a mock-up where the picture has to change its width from 1000 pixels to 700 pixels: Look at the code that follows: <div id="container"> <img src = "picture.jpg" width="1000" height="400"> </div> Assuming the HTML code looks like this, if we would add a responsive media query that resizes the container to match the width of the screen, we've to cut off a part of the picture. What we want to do is to scale the picture within the container to have the same or a smaller size than the container. The following CSS snippet can be added to any CSS file to make your pictures scale nicely in a responsive layout: img { max-width: 100%; height: auto; } Once you've added this little snippet, your picture will never get bigger than its parent container. The property max-width is pretty obvious; it restricts the maximum size. But why is height: auto necessary? If you look at the preceding HTML code, you can see that our picture has a fixed width and height. If we'd only specify max-width and look at the picture on a screen with a width of 500 pixels, we'd get a picture with the dimensions 500 x 400 pixels. The picture would be distorted. To avoid this, we specify height: auto; to make sure the height stays in relation to the width of the picture. Pictures on high-density screens If you printed some of your graphic ideas on a paper and not just displayed them on a computer screen, you'll probably have heard of pixels per inch (ppi) and dots per inch (dpi) before. It's a measure you can use to determine the number of pixels per inch. You'll get a higher density and more details if you have more pixels or dots per inch. You might have read about retina screens; those displays have a density of around 300 dpi, about twice as much as an average computer monitor. You don't have to, but it's nice if you also make sure that you give owners of such a device the chance to look at high-quality pictures. What's necessary to deliver a high-quality picture to a retina screen? Some of you might think that you have to save an image with more ppi; but that's not what you should do when creating a retina-ready site. Devices with a retina display simply ignore the pixels per inch information stored in an image. However, the dimension of your images matters. A picture saved for a retina display should have exactly twice the size of the original image. You could use an SVG picture instead but you still have to use a fallback picture because SVG isn't supported as well as image formats like PNG. In theory, SVG would be even better because it is vector-based and scales perfectly in any resolution. Enough theory, let's look at an example that uses CSS to display a different image for a retina display: #logo { background-image: url(logo.png); background-size: 400px 150px; width: 400px; height: 150px; } @media all screen and (-webkit-min-device-pixel-ratio: 2) { #logo { background-image: url(logo@2x.png); } } We've got an HTML element <div id="logo"></div> where we display a background picture to show our logo. If you look at the media query, you can see that we're checking a variable called –webkit-min-device-pixel-ratio to detect a high-resolution display. In case the display has a pixel ratio of 2 or higher, we're using an alternative picture that is twice the size. But note the width and height of the container stays the same. What alternatives are there? As we quickly mentioned, a vector-based format such as SVG would have some benefits but isn't supported on IE7 and IE8. However, you can still use SVG. But you have to make sure that there's a fallback image for those two browsers. Have a look at the following code: <!--[if lte IE 8]> <img src = "logo.png" width="200" height="50" /> <![endif]--> <!--[if gt IE 8]> <img src = "logo.svg" width="200" height="50" /> <![endif]--> <!--[if !IE]>--> <img src = "logo.svg" width="200" height="50" /> <!--<![endif]--> In the preceding code, we're using conditional tags to make sure that the old versions of Internet Explorer use the logo saved as PNG, but switch to SVG for modern browsers. It takes a bit more effort because you have to work with vectors and still have to save it as a PNG file, but if you want to make sure your logo or illustrations are nicely displayed when zoomed, use this trick. Working with SVG is an option, but there's another vector-based solution that you might want to use in some situations. A simple text is always rendered using vectors. No matter what font size you're using, it will always have sharp edges. Most people probably think about letters, numbers, and punctuation marks when they think about fonts, but there are icon fonts as well. Also keep in mind that you can create your own icon web font too. Check this site:http://fontello.com/ , which is a nice tool that allows you to select the icons you need and use it as a web font. You can also create your very own icon web font from scratch; check out the following link for a detailed tutorial: http://www.webdesignerdepot.com/2012/01/how-to-make-your-own-iconwebfont/ One last word before we continue; Retina screens are relatively new. It's therefore no surprise that some of the specifications to create a perfect retina layout are still drafts. The Web is a fast moving place; expect some changes and new features to insert an image with multiple sources and more vector features. Summary In this article, we learned about responsive themes that can be added to our themes and how media queries are an important part of responsive layouts. This article also helped you on how to scale pictures on different types of devices. It also helped you understand areas regarding what it takes to display websites for retina screens. Resources for Article : Further resources on this subject: concrete5: Mastering Auto-Nav for Advanced Navigation [Article] Everything in a Package with concrete5 [Article] Creating mobile friendly themes [Article]
Read more
  • 0
  • 0
  • 1669

article-image-role-center-pages
Packt
20 Mar 2013
6 min read
Save for later

Role Center pages

Packt
20 Mar 2013
6 min read
(For more resources related to this topic, see here. Featured Image credit: Music Oomph website) The standard NAV 2013 distribution from Microsoft includes 21 different Role Center pages, identified for user roles such as Bookkeeper, Sales Manager, Shop Supervisor, Purchasing Agent, and so on. Some localized NAV distributions may have additional Role Center pages included. It is critical to realize that the Role Centers supplied out of the box are not generally intended to be used directly out of the box. According to the Help section, Working with Role Centers, only 3 of the 21 supplied Role Centers have been fully configured. These three are: 9004 — Bookkeeper 9005 — Sales Manager 9006 — Order Processor The 21 Role Centers should be used as templates or models for custom Role Centers tailored to the specific work role requirements of the individual customer implementation. One of the critical tasks of implementing a new system will be to analyze the workflow and responsibilities of the system's intended users and configure Role Centers to fit the users. In some cases, the supplied Role Centers can be used with minimal tailoring. Sometimes, it will be necessary to create complete new Role Centers. Even then, we will often be able to start with a copy of an existing Role Center Page, which we will modify as required. In any case, it is important to understand the structure of the Role Center Page and how it is built. Role Center structure The following screenshot shows Page 9006 — Order Processor Role Center: The components of the Role Center highlighted in the preceding screenshot are: Action Ribbon Navigation Pane Activity Pane Cue Group Actions (in Cue Groups) Cues (in Cue Groups) Page Parts User's Outlook System Parts A general representation of the structure of a Role Center Page is shown in the following outline: We need to understand the construction of a Role Center page so that we are prepared to modify an existing Role Center or create a new one. First we'll take a look at Page 9006 – Order Processor Role Center in the Page Designer. The Role Center page layout should look familiar, because it's very similar in structure to the pages we've designed previously. What's specific to a Role Center page? There is a Container control of the RoleCenterArea SubType. This is required for a Role Center page. There are two Group Controls which represent the two columns (left and right) of the Role Center page display. Each group contains several parts which show up individually in the Role Center display. Role Center page properties are accessed by highlighting the first blank line on the Page Designer form (the line below all of the defined controls), then clicking on the Properties icon, or we could right—click and choose the Properties option, or click on View | Properties or press Shift + F4. Note that the PageType is RoleCenter, and there is no Source Table . Role Center activities page Since the Group Control has no underlying code or settings, we'll examine the first Part Control's properties. The PagePartId property is SO Processor Activities . Cue Groups and Cues Now we'll focus on Page 9060 — SO Processor Activities. Designing that page, we see the following layout. Comparing the controls we see here to those of the Role Center, we can see this Page Part is the source of the Activities section of the Role Center Page. There are three CueGroup Controls – For Release, Sales Orders Released Not Shipped and Returns. In each CueGroup, there are the Field Controls for the individual Cues. An individual Cue is displayed as an iconic shortcut to a filtered list. The size of the stack of papers in the Cue icon represents the number of records in that list. The actual number of entries is also displayed as part of the icon (see the Sales Orders — Open example in following screenshot). The purpose of a Cue is to provide a focus on and single click access to a specific user task. The set of Cues is intended to represent the full set of primary activities for a user, based on their work Role. Cue source table In the Properties of the SO Processor Activities page, we see this is a PageType of CardPart tied to SourceTable Sales Cue . Next we want to Design the referenced table, Sales Cue, to see how it is constructed. There we see a simply structured table, with an integer field for each of the Cues that were displayed in the Role Center we are analyzing. There is also a key field and two fields identified as Date Filters. When we display the properties of one of these integer fields, Sales Orders — Open, we find it is a FlowField providing a Count of the Sales Orders with a Status of Open: If we inspect each of the other integer fields in this table, we will find a similar FlowField setup. Each is defined to fit the specific Cue to which it's tied. If we think about what the Cues show (a count) and how FlowFields work (a calculation based on a range of data records), we can see this is a simple, direct method of providing the information necessary to support Cue displays. Clicking on the Cue (the count) then opens up the list of records being counted. The following screenshot shows the list of Cue tables. Each of the Cue tables contains a series of FlowFields that support a set of Cues. Obviously, some Cue tables service more than one of the Role Center pages. Cue Group Actions Another set of Role Center page components to analyze are the Cue Group Actions . While the Cues are the primary tasks that are presented to the user, the Cue Group Actions are a related secondary set of tasks displayed to the right of the Cues. Cue Group Actions are defined in the Role Center essentially the same way as Actions are defined in other page types. As the name implies, Cue Group Actions are associated with a Control with the SubType CueGroup . If we right— click on the CueGroup Control, one of the options available is Control Actions (as shown in the following screenshot): When we choose Control Actions , the Action Designer form will be displayed showing the two CueGroup actions in the For Release CueGroup in the SO Processor Role Center page. If we open the Properties window we will see the "New" functionality is accomplished by setting the RunPageMode property to Create.
Read more
  • 0
  • 0
  • 2954
article-image-collaborative-work-svn-and-git
Packt
19 Mar 2013
11 min read
Save for later

Collaborative Work with SVN and Git

Packt
19 Mar 2013
11 min read
(For more resources related to this topic, see here.) Working with SVN At first we will take a look at the SVN perspective.The SVN perspective provides a group of views that help us to work with a Subversion server. You can open this perspective by using the Perspective menu in the top-right of the Aptana Studio window. The important and most frequently used views related to SVN, which we will take a look at, are the SVN Repositories view, the Team | History view, and the SVN | Console view. These views are categorized as the views selection into the SVN and Team folder, as shown in the following screenshot:     The SVN Repositories view allows you to add new repositories and manage all available repositories. Additionally, you have the option to create new tags or branches of the Repository. These views belong to the SVN views, as shown in the following screenshot: The History view allows you to get an overview about the project and revisions history. This view is used by SVN and Git projects; for this reason the view is stored in the Team views group. The History view can be opened by the menu under Window | Show View | History. Here you can see all the revisions with their comments and data creation. Furthermore, you can get a view into all revisions of a file and you also have, the ability to compare all revisions. The following screenshot shows the History view: Within the SVN Console view, you will find the output from all the SVN actions that are executed by Aptana Studio. Therefore, if you have an SVN conflict or something else, you can take a look at this Console view's output and you might locate the problem a bit faster. The SVN Console view was automatically integrated in the Aptana Studio Console, while the SVN plugin was installed. So if you need the SVN Console view, just open the general Console view from Window | Show view | Console. If the Console view is open, just use the View menu to select the Console type, which in this case is the SVN Console entry. The following screenshot shows the Console view and how you can select SVN Console: However, before we can start work with SVN, we have to add the related SVN Repository. Time for action – adding an SVN Repository Open the SVN perspective by using the Perspective menu in the top-right corner of the Aptana Studio window. Now, you should see the SVN Repositories view on the left-hand side of the Aptana Studio window. If it does not open automatically, open it by selecting the view from the navigation Window | Show view | SVN Repositories. In order to add a new SVN Repository, click on the small SVN icon with the plus sign at the top of the SVN Repositories view. You will now have to enter the address of the Subversion server in the pop up that appears, for example, svn://219.199.99.99/svn_codeSnippets. After you have clicked on the Finish button, Aptana Studio tries to reach the Subversion server in order to complete the process of adding a new Repository. If the Subversion server was reached and the SVN Repository is password protected, you will have to enter the access data for reading the SVN data. If you don't have the required access data available currently, you can abort the process and Aptana Studio will ask you whether you want to keep the location. If you click on NO, the newly added SVN Repository will be deleted, but if you click on YES, the location will remain. This allows you to retrieve the required access data later, enter them, and begin to work with the SVN Repository. Regardless of whether you keep the location or enter the required access data, the new SVN Repository will be listed in the SVN Repository view. What just happened? We have added a new SVN Repository into Aptana Studio. The new Repository is now listed in our SVN Repositories view and we can check this out from there, or create new tags or branches. Checking out an SVN Repository After we have seen how to add a new SVN Repository to Aptana Studio, we also want to know how we can check this Repository in order to work with the contained source code. You can do this, like many other things are done in Aptana Studio, in different ways. We will take a look at how we can do this directly from the SVN Repositories view, because every time we add a new Repository to Aptana Studio, we will also want to check it and use it as a project. Time for action – checking out an SVN Repository Open the SVN Repositories view. Expand the SVN Repository that you wish to check out. We do this because we want to check out the trunk directory from the Repository, not the tags and branches directory. Now, right-click on the trunk directory and select the Check Out... entry. Aptana Studio will now read the properties of the SVN Repository directly from the Subversion server. When all the required properties are received, the following window will appear on your screen: First of all, we select the Check out as a project in the workspace option and enter the name of the new SVN project. After this, we select the revision that we want to check out. This is usually the head revision. This means that you want to check out the last committed one—called the head revision. But you can check out any revision number you want from the past. If this is so, just deselect the Check out HEAD revision checkbox and enter the number of the revision that you want to check out. In the last section, we select the Fully recursive option within the Depth drop-down list and uncheck the Ignore externals checkbox, but select the Allow unversioned obstructions checkbox. After you have selected these settings, click on the Next button. Finally, you can select the location where the project should be created. Normally, this is the current workspace, but sometimes the location is different from the workspace. Maybe you have a web server installed and want to place the source code directly into the web root, in order to run the web application directly on your local machine. Finally, whether you select a different location for the project or not, you have to click on the Finish button to finalize the "Check out" into a new project. What just happened? We have checked out an SVN Repository from the SVN Repositories view. In addition to that, we have seen how we can also check out the Repository source code into another location other than the workspace. Finally, you should now have a ready SVN project where you can start working. File states If you're now changing some lines within a source code file, the Project Explorer view and the App Explorer view change the files' icon, so that you see a small white star on the black background. This means the file has changed since the last commit/update. There are some more small icons, which give you information about the related files and directories. Let's take a closer look at the Label Decorations tab as shown in the following screenshot: Now, we will discuss the symbols in the order shown in the previous screenshot: The small rising arrow shows you that the file or directory is an external one. The small yellow cylinder shows you that the file or directory is already under version control. The red X shows you that this file or directory is marked for deletion. The next time you commit your changes, the file will be deleted. The small blue cylinder shows you that the file or directory is switched. These are files or directories that belong to a different working copy other than their local parent directory. The small blue plus symbol shows you that this already versioned file or directory needs to be added to the repository. These could be files or directories you may have renamed or moved to a different directory. The small cornered square shows you that these files have a conflict with the repository. The small white star on the black background shows you that these files or directories have been changed since the last commit. If the file's or directory's icon has no small symbol, it means the file is ignored by the SVN Repository. The small white hook on the black background shows you that this file or directory is locked. The small red stop sign shows you that this file or directory is read-only. The small yellow cylinder shows you that this file or directory is already under version control and unchanged since the last commit. The small question mark shows you that this new file or directory isn't currently under version control. If you didn't find your icons in this list, or your icons look different, no problem. Just navigate to Window | Preferences and select the Label Decorations entry under Team | SVN within the tree. Here you will find all of the icons which are used. Committing an SVN Repository If you have finished extending your web application with some new features, you can now commit these changes so that the changes are stored in the Repository, and other developers can also update their working copies and get the new features. But how can you simply commit the changed files? Unlike a Git Repository, SVN allows you to commit changes in a tree from the Repository. By using Git, you can only commit changes in the complete Repository at once. But for now, we want to commit our SVN Repository changes, therefore just follow the steps mentioned in the following Time for action – updating and committing an SVN Repository section. Time for action – updating and committing an SVN Repository The first step, before performing a commit, is to perform an update on your working copy. Therefore, we will start by doing this, Aptana Studio reads all new revisions from the Subversion server and merges them with your local working copy. In order to do this update, right-click on your project root and select Team | Update to HEAD. When your working copy is up to date, navigate to the App Explorer view or the Project Explorer view and right-click on the files or directories that you want to commit, and then select the Commit... entry in the Team option. If you select a few directories or the whole project, the Commit window lists only those files within the selection that have changed since the last commit. So, you are able to select just the files and directories that you want to commit. Compose the selected files and directories as you need, and enter a comment in the top of the window. Why do you have to enter a comment while committing a change? Because, by committing the SVN Repository, it automatically saves the date, time, and your username; with this data the revision history stores information about who has changed which file at what time. In addition to that comes the commenting part. The comment should describe what kind of changes were made and what is their purpose. To finalize the commit, you just have to click on the OK button and the commit process will start. As described previously, you can see the output from all your SVN processes within the SVN Console view. In the following screenshot you can see the result of our commit process: What just happened? We have updated our working copy in order to commit our changes. Now the other developers can update their working copies too and can then work with your extensions. It should be noted again that it's recommended to perform an update before every commit. You can perform an update in a single file tree node. You don't have to update your whole project every time, a single node can also be committed. Updating an SVN Repository Additionally, similar to the SVN check out, you have the option to update your working copy not only to the Head revision, but also to a special revision number. In order to do this, right-click on the project root within the Project Explorer view and select the Update to Head... option or the Update to Version... option under the Team tab. After selecting one of these entries, Aptana Studio determines all the new files and files to be updated, downloads them from the Repository, and merges them with your local working copy. Now you should have all the source code from your current project. But, how can you identify which parts of a file are new or have been changed? No problem! Aptana Studio allows you not only to compare two different local files, you can also compare files from different revisions in your Repository. Refer to the following Time for action section to understand how this works:
Read more
  • 0
  • 0
  • 2195

article-image-remotely-preview-and-test-mobile-web-pages-actual-devices-adobe-edge-inspect
Packt
19 Mar 2013
8 min read
Save for later

Remotely Preview and test mobile web pages on actual devices with Adobe Edge Inspect

Packt
19 Mar 2013
8 min read
(For more resources related to this topic, see here.) Creating a sample mobile web application page for our testing purpose Let's first check out a very simple demo application that we will set up for our test. Our demo application will be a very simple structured HTML page targeted for mobile browsers. The main purpose behind building it is to showcase the various inspection and debugging capabilities of Adobe Edge Inspect. Now, let's get started by creating a directory named adobe_inspect_test inside your local web server's webroot directory. Since I have WAMP server installed on my Windows computer, I have created the directory inside the www folder (which is the webroot for WAMP server). Create a new empty HTML file named index.html inside the adobe_inspect_test directory. Fill it with the following code snippet: <html> <head> <title>Simple demo</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"/> <style type='text/css' > html, body, p, div, br, input{ margin:0; padding:0; } html,body{ font-family:Helvetica; font-size:14px; font-weight:bold; color:#222; width:100%; height:100%; } #wrapper{ width:100%; height:100%; overflow:hidden; } .divStack{ padding:10px; margin:20px; text-align:center; } #div1{ background:#ABA73C; } #div2{ background:#606873; } input[type=button] { padding:5px; } <script type="text/javascript"> window.addEventListener('load',init,false); function init() { document.getElementById('btn1').addEventListener ('click',button1Clicked,false); document.getElementById('btn2').addEventListener ('click',button2Clicked,false); } function button1Clicked() { console.log('Button 1 Clicked'); } function button2Clicked() { console.log('Button 2 Clicked'); } </script> </style> </head> <body> <div id="wrapper"> <div id="div1" class="divStack"><p>First Div</p></div> <div id="div2" class="divStack"><p>Second Div</p></div> <div class="divStack"> <input id="btn1" type="button" value="Button1" /> <input id="btn2" type="button" value="Button2" /> </div> </div> </body> </html> As you can make out we have two div elements (#div1 and #div2) and two buttons (#btn1 and #btn2). We will play around with the two div elements, make changes to their HTML markup and CSS styles when we start remote debugging. And then with our two buttons we will see how we can check JavaScript console log messages remotely. Adobe Edge Inspect is compatible with Google Chrome only, so throughout our testing we will be running our demo application in Chrome. Let’s run the index.html page from our web server. This is how it looks as of now: Now, let’s check if the two buttons are generating the console log messages. For that, right-click inside Chrome and select Inspect element. This will open up the Chrome web developer tools window. Click on the Console tab. Now click on the two buttons and you will see console messages based on the button clicked. The following screenshot shows it: Everything seems to work fine and with that our demo application is ready to be tested in a mobile device with Adobe Edge Inspect. With the demo application running in Chrome and your mobile devices paired to your computer , you will instantly see the same page opening in the Edge Inspect client app in all your mobile devices. The following image shows how the page looks in an iPhone paired to my computer. Open the Edge Inspect web inspector window Now that you can see our demo application in all your paired mobile devices we are ready to remotely inspect and debug on a targeted mobile device. Click on the Edge Inspect extension icon in Chrome and select a device for inspection. I am selecting the iPhone from the list of paired devices. Now click on the Remote Inspection button to the right of the selected device name. The following image should help you: This will open up the Edge Inspect web inspector window also known as the weinre (WEb INspector REmote) web inspector. This looks very similar to the Chrome web inspector window, doesn't it? So if you have experience with the Chrome web debugging tools then this should look familiar to you. The following screenshot shows it: As you can see, by default the Remote tab opens up. The title bar says target not connected. So, although your mobile device is paired it is not yet ready for remote inspection. Under Devicess you can see your paired mobile device name with the URL of the page opened in it. Now, click on the device name to connect it. As soon as you do that, you will notice that it turns green. Congratulations! You are now ready for remote inspection as your mobile device is connected. The following screenshot shows it: Changing HTML markup and viewing the results Your target mobile device (the iPhone in my case) and the debug client (the Edge Inspect web inspector) are connected to the weinre debug server now and we are ready to make some changes to the HTML. Click on the Elements tab in the Edge Inspect web inspector on your computer and you will see the HTML markup of our demo application in it. It may take a few seconds to load since the communication is via Ajax over HTTP. Now, hover your mouse over any element and you would instantly see it being highlighted in your mobile device. Now let's make some changes to the HTML and see if it is reflected in the target mobile device. Let's change the text inside #div2 from Second Div to Second Div edited. The following screenshot shows the change made in #div2 in the Edge Inspect web inspector in my computer: And magic! It is changed on the iPhone too. Cool, isn't it? The following screenshot shows the new text inside #div2. This is what remote debugging is all about. We are utilizing the power of Adobe Edge Inspect to overcome the limitations of pure debugging tools in mobile browsers. Instead make changes on your computer and see them directly in your handset. Similarly you can make other markup changes such as removing an HTML element, changing element properties, and so on. Changing CSS style rules Now, let's make some CSS changes. Select an element in the Elements tab and the corresponding CSS styles are listed on the right. Now make changes to the style and the results will reflect on the mobile device as well. I have selected the First Div (#div1) element. Let's remove its padding. Uncheck the checkbox against padding and the 10 px padding is removed. The following screenshot shows the CSS change made in the Edge Inspect web inspector on my computer: And the following image shows the result being reflected on the iPhone instantly: Similarly, you can change other style rules such as width, height, padding, and margin and see the changes directly on your device. Viewing console log messages Click on the Console tab in the Edge Inspect web inspector to open it. Now click/tap on the buttons one by one on your mobile device. You will see that log messages are being printed on the console for the corresponding button clicked/tapped on the mobile device. This way you can debug JavaScript code remotely. Although Edge Inspect lacks JavaScript debugging using breakpoints (which would have been really handy had we been able to watch local and global variables, function arguments by pausing the execution and observing the state) but nevertheless, by using the console messages you can at least know that your JavaScript code is executing correctly to the point where the log is generated. So basic script debugging can be done. The following screenshot shows the console messages printed remotely from the paired iPhone: Similarly you can target another device for remote inspection and see the changes directly in the device. With that we have covered how to remotely debug and test web applications running on a mobile device browser. Summary In this article, we have seen the most important feature of Adobe Edge Inspect, that is, how we can remotely preview, inspect, and debug a mobile web page. We first created a sample mobile web page, edited it using Adobe Edge Inspect, changed the HTML markup and CSS styles by remote testing, and saw the results as to how this special feature of Adobe Edge Inspect is utilized. Resources for Article : Further resources on this subject: Adapting to User Devices Using Mobile Web Technology [Article] Getting Started on UDK with iOS [Article] Getting Started with Internet Explorer Mobile [Article]
Read more
  • 0
  • 0
  • 4588
Modal Close icon
Modal Close icon