Parameters and Loops in snippets - sublimetext2

I would like to make a snippet that makes an HTML table.
Here are some examples of things to type :
table name address city
- table team wins losses draws
- table views clicks clickthrough
This is what I want it to output : a table with a columns for each of the fields (with 'table' triggering the snippet).
I'd also like to run these field names through a function to transform them (for example to field names - "First Name" -> 'first_name'.
Is this possible? How would I do it?

Not exactly what you want, but I would go with Emmet (here is a handy cheet sheet). There is a Sublime package available, so it's easy to install. It might be a little overwhelming at first, but once you start to use it, you will get the hang of it and it will speed up your html/css production.
Type table>tr*3>th and hit tab at the end. This will produce:
<table>
<tr>
<th></th>
</tr>
<tr>
<th></th>
</tr>
<tr>
<th></th>
</tr>
</table>
Then you can tab to the ths to type in your column headers.

Related

Scripting Issue with Netsuite Advanced PDF/HTML Template

I need help with the Freemarker format for Netsuite (Advanced PDF/HTML Templates)
There are 3 important data values pulled for this records;
${item.quantity} *Order Value*
${item.fulfilled} *Fulfilled Value*
${item.backordered} *Backorder Value*
Basically, what I try to accomplish is, to only show items that are "on backorder"
However this task seems to be a much harder than I have the time and skill for.
So, my plan B is using a separate template for the backorders (which is working well so far!)
The problem is that if I came across an item which is a NON-INVENTORY item, Netsuite does not calculate any qty for ${item.backordered}
SO
Is there any way I can "calculate" the backorder value with scripting in the template?
Can I use an arithmetic function (like below)?
item.quantity - item.fulfilled = item.backordered
Here is the basic format of the text surrounding this query;
<#if record.item?has_content>
<table><#list record.item as item><#if item_index==0>
<thead>
<tr>
<th> QTY </th>
</tr>
</thead>
</#if>
<tr>
<td> ${item.backordered} </td>
</tr>
</#list></table>
</#if>
I have a basic understanding of HTML and CSS, but scripting is still very new to me, so please only constructive criticism.
Try adding the following Freemarker helper function to your template:
<#function toNumber val>
<#if val?has_content && val?length gt 0 >
<#return val?html?replace('[^0-9.]','','r')?number >
<#else>
<#return 0 >
</#if>
</#function>
This will ensure that all fields are correctly parsed as numbers, and you should be able to perform mathematical calculations on the fields without errors.
So you can replace:
<td> ${item.backordered} </td>
with:
<td> ${toNumber(item.quantity) - toNumber(item.fulfilled)} </td>
See the answer to suitescript set custom column value netsuite for an example that uses arithmetic on line item values.
So I believe the root problem lays with the Java JAR NetSuite is using. It appears it has a null pointer bug with empty int/number type values.
I would recommend adding a UserEvent script to change the values to zero that are empty. This will prevent the error you are getting. You should be able to catch the PRINT type on the before load event. If the zero value is not carried over to the template, you can add a custom column field that is not stored and push the value there.

Creating a dynamic table In HTML and AngularJS from contents of a Javascript array

I need help creating a dynamic table in the format of a round robin competition using HTML and AngularJS. An array of strings will be given and then the table will be created based on how many names were in the list so part of the table will be generated dynamically and part of the table will always be the same. This is an example of a table that would be generated if I passed an array with 8 names. Only columns A, B, and C should have any information when the table is generated though I kept everything blank for simplicity's sake. The rest of the boxes should all be text input fields.
Until now most of the tables I have done have been pretty simple and I am a little out of my depth here, any help would be much appreciated.
Assuming you always have a full 8 teams this would get you started
<table>
<tr>
<th>club</th>
<th>team</th>
<th>#</th>
<th ng-repeat="item in items">{{$index+1}}</th>
<th>V</th>
<th>TS</th>
</tr>
<tr ng-repeat="item in items">
<td>{{item.club}}</td>
<td>{{item.team}}</td>
<td>{{item.rank}}</td>
<td ng-repeat="item in items" ng-class="{black:$index==$parent.$index}"></td>
<td><input ng-model="item.v"></td>
<td><input ng-model="item.ts"></td>
</tr>
</table>
DEMO
This is a really nice example of using nested ng-repeat elements.
Please see this plunker for a working demo.
The main trick for detecting when to black out a box is to use ng-init="$rowIndex=$index" on the outer ng-repeat (where we generate a row for each entry). This allows the inner ng-repeat (where we generate a column for each entry) to have an ng-class="{'blackout': $index==$rowIndex}"

To create xpath for html table to access desired record using 3 inputs

This is a structure of very basic html table. I want to create xpath for following scenario.
I will insert 2 field names like 'Name' and 'Salary' along with value of 'Name' field (say for example 'STU') then output should be 25k.
I was given hint like
string (xpath which will have 2 field names and one value) output of this function will be that key.
<html>
<body>
<h3>MY TABLE</h3>
<table>
<tbody>
<tr>
<th>id</th>
<th>Name</th>
<th>date</th>
<th>Address</th>
<th>salary</th>
</tr>
<tr>
<td>XYZ</td>
<td>STU</td>
<td>12/20/2015</td>
<td>Mumbai</td>
<td>25k</td>
</tr>
<tr><td>PQR</td>
<td>ABC</td>
<td>01/05/2015</td>
<td>Chennai</td>
<td>25k</td>
</tr>
<tr>
<td>ABC</td>
<td>PQR</td>
<td>03/09/2015</td>
<td>Bangalore</td>
<td>20k</td>
</tr>
<tr>
<td>emp4</td>
<td>XYZ</td>
<td>08/12/2015</td>
<td>Delhi</td>
<td>30k</td>
</tr>
</tbody>
</table>
</body>
</html>
Basics:
The first thing you will need to do is find which column(s) in the table contain(s) the field(s) you are searching for.
For example, to find the position of the Name column:
count(//tbody/tr/th[./text() = 'Name']/preceding-sibling::th) + 1
The above will return 2. (Of course, this technique won't necessarily work well if there are colspan attributes used in the HTML, but there are none in your example.)
Then, you can find the rows that contain a specific value in this column - for example STU - in this column like this:
//tbody/tr/td[position() = $WherePosition][./text() = 'STU']/..
Notice the use of the variable $WherePosition above. Here, I have used it to represent the result of the previous query (1). Depending on what tool you are using to perform the XPath query, you may or may not have the option to set variables. If you wish to use a single XPath expression or you don't want to or can't use variables, you can simply replace it with the previous XPath expression, although it will become less readable.
It's worth noting that aside from readability, variables will also make it easier to re-use the same expression, because you can, for example, substitute 'Name' in the first query for $WhereField, if you tell the XPath evaluator that you want to set the $WhereField variable to Name. And in the query to find the specific row (2), you can substitute 'STU' for $WhereValue, if you also set this variable accordingly.
Apply it:
Now to get the position of the salary column. If you used my tip above about using variables, you could re-execute the same expression as (1) again, but with the $WhereField variable set to salary instead of Name. i.e. count(//tbody/tr/th[./text() = $WhereField]/preceding-sibling::th) + 1
And if you stored the result of query (2) as a variable called $matching_rows and the salary column position as $SalaryPosition, then to return the salary for the row where Name = STU, you could simply finish with: $matching_rows/td[position() = $SalaryPosition]/text(), and you would get the answer 25k.
TL;DR
In summary, as an XPath 1.0 one-liner to get the salary for the row with Name = STU:
//tbody/tr/td[position() = count(//tbody/tr/th[./text() = 'Name']/preceding-sibling::th) + 1][./text() = 'STU']/../td[position() = count(//tbody/tr/th[./text() = 'salary']/preceding-sibling::th) + 1]/text()

How can I support rule definition from a user for my business logic processing?

I have a case where I have an existing method that does a specific kind of processing. I have setup a database table that it checks and if a specific value in a column exists it uses the value in one of the columns.
Example: let's say that I have a method that charges a user. And I have in the table a row that has a column for the country and a column for reduction percentage. So while I am processing the user if the user's country exists in the table I use the value of the column to reduce the price. So far so good.
My question is how could I enhance my design in order to add more general/complex rules?
E.g. I would like to support some kind of interface that the user specifies rules e.g. a user's age or a product weight etc and based on this rules my code processing can figure out how to apply them?
I mean how could I extend my simple table and business logic processing with the country/percentage values to a small rule based setup?
I don't need really complex rules. Just the ability to be let the define a rule if needed
You have to support a certain set of operators, as well as possible fields to be checked against the rule and certain events when the rule is fullfilled.
I would suggest something like this: jsFiddle
<table>
<tr>
<td>Field</td>
<td>
<select><option>Country</option><option>Age</option></select>
</td>
</tr>
<tr>
<td>Operator</td>
<td><select><option>greater than</option><option>smaller than</option><option>not empty</option></select>
</td>
</tr>
<tr>
<td>Value</td>
<td><input id="value" type="text" /></td>
</tr>
<tr>
<td>action</td>
<td><select><option>10% discount</option><option>other stuff</option><option>other stuff 2</option></select></td>
</tr>
</table>
That's just a very quick example of how it could look. You can add any operators and actions you want. You could also include a target field for example. But what's actually in the dropdowns depends on your requirements.

Timeline getting data from database

Timeglider is a timeline project.
Timeglider is a jQuery plugin for displaying any number of events in a highly-flexible timeline.
One of the easiest way for fetching and reading data is using a TABLE.
this TABLE is a HTML TABLE that have a specific properties
for example we should create table with its data in SQL.
I use the objects like GRIDVIEW or (TABLE and panel) but these are not have those tags.
please help me
may i use json datasource? but i dont know how?
but with table it is easier.
Timeglider timelines can load directly from data you provide in an
HTML table.
may i use with response.write ? or another proposed way?
or add hese line to table. (i know only gridview have property header) but table doesnt??!!!!
please help me.
<!-- The first row of the table is reserved for meta-data.
Class values below are *critical* for mapping out data from the
<td> elements that follow --- though order is not important.
The text in <td> elements is *not* critical: just the class names.
-->
<tr>
<th class="tg-startdate">start date</th>
<th class="tg-enddate">end date</th>
<th class="tg-title">title</th>
<th class="tg-description">description</th>
<th class="tg-icon">icon</th>
<th class="tg-importance">importance</th>
<th class="tg-link">link</th>
</tr>
i solve it by creating my desired HTML code and with
Response.Write();
fire it in the output
and Timeglider is also work good