ClientTemplate issue with Kendo Grid column - kendo-ui

I am trying to configure a Kendo Grid column to display and edit a TimeSpan? property (yeah, I know...), but to do do I have mapped the TimeSpan? to a simpler TimeOfDay model, with just Hours, Minutes, and Seconds properties.
I have gleaned little from the Kendo documentation, which in itself is, no other words describe it, pathetic; worthy only of some sloppy little open source project, but relies on forum questions and answers. In other words, only document what people ask, and at that, rely on the free help of forum members. Rant over.
My column definition looks like this:
columns.Bound(p => p.StartTime).ClientTemplate("#if (StartTime != null) {#= Hours + ':' + Minutes #} else {#= '' #} #");
The output from that is
= Hours ':' Minutes
for non-null values and
= ''
for null values.
Please, for the love of God, someone tell me what I'm doing wrong, and as a bonus, refer me to an explanation, not a bunch of bloody unsuitable examples labelled 'Documentation'.

The template definition is invalid because the starting # isn't closed. You can try with this:
"#if (StartTime != null) { # #= Hours # : #= Minutes # #} else {# #}#"
It would be easier to explain if it is split on multiple rows:
"# if (StartTime !=null) { #" +
"#= Hours # : #= Minutes #" +
"# } else { #" +
" " +
"# } #"
The the # code # statement is used to embed executable JavaScript code which doesn't output anything. The #= code # statement is used to output raw values (no HTML encoding). The #: code # statement will html encode the output.
Here is a live demo: http://jsbin.com/ecunuh/1/edit

Related

Format Date() in VFP report

I use database program written in VFP and I am trying to change a date format in a report generated by that program.
The current field in the report is DATE() which returns DD/MM/YYYY
I'd like the field to return DDMMYY (ie no seperators, no century and single digit days and months to have a leading zero)
Can someone tell me the report field expression I should use to achieve this?
Thanks
I solved this problem by creating a procedure and call that procedure as
date2(date(), "", 2, 2, 2) in report field.
This will print 150418
This function can also be used with default value i.e. date(date()) which will print 15-Apr-18
FUNCTION date2(par_date, par_separtor, par_day_digit, par_month_digit, par_year_digit)
LOCAL date_return, day_t, month_t, year_t
IF VARTYPE(par_separtor) <> "C"
par_separtor = "-"
ENDIF
IF VARTYPE(par_year_digit) <> "N"
par_year_digit = 2
ENDIF
day_t = IIF(DAY(par_date)<10, '0', "") + allt(str(DAY(par_date)))
month_t = PROPER(allt(left(CMONTH(par_date),3)))
year_t = right(allt(str(year(par_date))),par_year_digit)
IF VARTYPE(par_month_digit) = "N"
month_t = IIF(MONTH(par_date)<10, '0', "") + allt(STR(MONTH(par_date)))
* MESSAGEBOX(month)
ENDIF
date_return = IIF(EMPTY(par_date), " ", day_t + par_separtor + month_t + par_separtor + year_t)
RETURN date_return
ENDFUNC
Before report set the century off if it is not already (you could do this even if you only have access to report itself, either in report environment or bands code):
Set century off
Then the expression is simply:
CHRTRAN(DTOC(DATE()),'/','')
Or if you meant a date field:
CHRTRAN(DTOC(myDateField),'/','')
If, for any reason, you can't use "set century off" (and it is ON) then change the expression slightly:
Stuff(CHRTRAN(DTOC(myDateField),'/',''),5,2,'')
Maybe this one is better and works regardless of date/datetime settings:
PADL(DAY(DATE())*10000+MONTH(DATE())*100+YEAR(DATE())%100,6,'0')
(if it is a date fieldthen replace date() with the field name)

How do I detect the presence of this line?

This question is related to a previous one I just asked here, so forgive me if much of the language seems similar.
I have a string that has multiple lines. What I am doing is checking each line for specific characteristics and then treating them accordingly.
One characteristic is if the line begins with a + or a -. That works just fine.
Another characteristic is if it contains nothing but a \n, and Ilya helped me figure out how to detect those lines, so that's good.
The last type of string I am trying to detect is those that don't match any of the above criteria, but come AFTER a line that begins with either a - or +.
Taken out of context, this is an example of a valid string I would like to find: " end\n",
However, here is a more complete example within the context of being after a line that begins with + or -.
"+ Reflection.add_reflection self, name, reflection\n",
" end\n",
" \n",
"- habtm_reflection = ActiveRecord::Reflection::HasAndBelongsToManyReflection.new(name, scope, options, self)\n",
In this particular instance, I am trying to pick out the second line.
Here is an instance where strings that match the pure string matching parameter would be disqualified because they come BEFORE a string that starts with a - or a +.
" #\n",
" # All of the association macros can be specialized through options. This makes cases\n",
" # more complex than the simple and guessable ones possible.\n",
"- module ClassMethods\n",
I hope that's clear.
Edit 1
To provide more clarity on what I am looking for. Basically I have broken the string into a bunch of lines and then I am iterating over each line.
So this is what I have done:
<% diff.body.lines.each do |dl| %>
<% if dl.start_with?("-") %>
<% elsif dl.start_with?("+") %>
<% elsif dl.strip.empty? %>
<% end %>
<% end %>
So what I want to do is to either modify the above set of if statements to accommodate this latest line check, or find some way to check it by adding another elsif condition....although considering that I need to know what happened to the line above I am not seeing how to do that without modifying this if statement.
str = [
"+ Reflection ...\n",
" end\n",
" \n",
"- habtm_reflection = ...\n"].join
str[/(^[+-].*$)\n(?!\n)(^[^+-].*$)/, 2]
#⇒ " end"
The regular expression basically looks up the line that is started with either + ot - (with (^[+-].*$)), skips the \n and then matches the line that is not started with one of + or - (with (^[^+-].*$).)

Does ruby's case statement fall through?

I am writing a hangman game in ruby and I wanted to use a case statement to determine which body part to place corresponding to a number of incorrect guesses. I made this game using a board class I use for other games like chess and connect-4 because I have a method which serializes the board class allowing me to save and load the game without any extra code. For the game to be saved, I needed some way of determining the number of incorrect guesses for the hangman without adding extra variables to the board class. To solve this I used an instance variable on the board class called history, which can be used to push moves from the game to the boards history. When the board gets serialized, the history is saved as well, which can be read by the game and used to determine incorrect guesses.
In the hangman game, I have a method called read history (which I use for all the games since it solves the serialization issue described above). The read_history method is responsible for reading the past guesses, display them, and determine the number of incorrect guesses. This number is then passed to a hang method which determines which body parts of the hangman to add.
def hang(incorrect)
case incorrect
when 0
#hangman = [" ", " ", " "]
break
when 7
#hangman[2][2] = '\\'
when 6
#hangman[2][0] = '/'
when 5
#hangman[2][1] = '*'
when 4
#hangman[1][2] = '\\'
when 3
#hangman[1][0] = '/'
when 2
#hangman[1][1] = '|'
when 1
#hangman[0][1] = 'o'
end
end
If I were writing this in java, and a value of 5 were passed to the above method, it would read the statement until it hit "when 5" or in java terms "case 5:". It would notice that there is not a break in the statement and will move down the list executing the code in "case 4:" and repeating until a break is found. If 0 were passed however it would execute the code, see the break, and would not execute and other statements.
I am wondering if Ruby is capable of using case statements the way java does in the way that they fall through to the next statement. For my particular problem I am aware that I can use a 0.upto(incorrect) loop and run the cases that way, but I would like to know the similarities and differences in the case statement used in ruby as opposed to the switch-case used in java
No, Ruby's case statement does not fall through like Java. Only one section is actually run (or the else). You can, however, list multiple values in a single match, e.g. like this site shows.
print "Enter your grade: "
grade = gets.chomp
case grade
when "A", "B"
puts 'You pretty smart!'
when "C", "D"
puts 'You pretty dumb!!'
else
puts "You can't even use a computer!"
end
It's functionally equivalent to a giant if-else. Code Academy's page on it recommends using commas to offer multiple options. But you can still won't be able to execute more than one branch of logic.
It does not fall through.
Ruby just doesn't have the same behavior as Java for this type of statement.
If you want to simulate the fall through behavior, you can do something like this:
def hang(incorrect)
#hangman = [" ", " ", " "]
#hangman[2][2] = '\\' if incorrect > 6
#hangman[2][0] = '/' if incorrect > 5
#hangman[2][1] = '*' if incorrect > 4
#hangman[1][2] = '\\' if incorrect > 3
#hangman[1][0] = '/' if incorrect > 2
#hangman[1][1] = '|' if incorrect > 1
#hangman[0][1] = 'o' if incorrect > 0
#hangman
end

Syntax error ... Jython/Python

Hi I'm doing my first programming assignment (it's with Jython, i.e. Python using Java) and I've run into a syntax error on line 14 (bolded below). I've tried changing the variable to something less useful like "L" or "I" but it still gives the error. It's annoying because it makes no sense. I have tried indenting again and adding comments around it.
This is a program that outputs a picture of a soccer ball factory. It's as much as an artistic project as a comp sci project. So the printing looks complicated but is only like long checklist for building.
def prettyPic():
#building materials and parts
spacer = " "
ceiling_part = "-"
ball = "o"
wheel = ""
door_joint = "#"
left_half_arch = "/"
right_half_arch = "\\"
ladder = "\\"
wall = "|"
glass = (
#biox
**left_box = "u"
right_box = "u"**
#begin printing
print (spacer*30 + ceiling_part*30)
print (spacer*32 + wall*1) + (spacer*47 + wall*1)
#three balls, leaving space for drop
print (spacer*32 + wall*1) + (ball*27) + (wall*1)
#arches, not touching ceiling
etc, etc
The problem is in this line:
glass = (
This means that to glass variable, you assign tuple just like:
glass = (1, 2, 'some string')
Python interpreter searches for termination of just opened tuple but it finds only Python code that is not correct in this context.
Remove or comment out line with glass, or assign to glass variable some value.

struggling with my pseudocode

I'm about to build a program written in pseudocode. I've already done most of the work , but I'm stuck on the code and I don't know what to do exactly. im a begginer and not everything is clear to me ...in one of the tasks i have to do , i have to make the program ask for the players name , which will be stored as a string then the program has to check if it exceeds the limit between 2/20 characters and inform the user if the input is wrong . i have researched and tried to figure out how i might be able to fix my code but i have a really short amount of time left and coudn't find anything regarding my problem :/ . this is the code ive done for this specific task. i know its wrong but i just dont know how to fix it . any help with be much appreciated . Thanks in advance :)
pseudocode:
// Getting user's name
valid = false
loop until valid is equal to true
Output" please enter your name "
Input playName
If (playName is => 1)AND(=<20)then
Valid = true
Otherwise
output "name exceeds the character limit"
I'm not sure what the syntax of your pseudo code is but :
assuming tabulation has meaning, you may have forgot to indent some lines to include them in the loop
'valid' is first declared with a lower case first letter so you may continue referencing it same way in line "Valid = true" -> "valid = true"
In the 'If' you want to test the lenght of the String and not compare the string to an int so maybe call a function length(String) that would return the length of the string or access a string.length attribute (as you wish in pseudo code)
You want the playName to be superior or equal to 2 "length(playName) >= 2" and inferior or equal to 20 "length(playname) <= 20"
The commonly used keyword meaning Otherwise is 'Else' as in
IF (Condition) THEN (code) ELSE (code)
I may modify you code like this :
// Getting user's name
valid = false
loop until valid is equal to true
Output" please enter your name "
Input playName
If (length(playName) >= 2) AND (length(playName) <= 20)
Then
valid = true
Else
output "name exceeds the character limit"

Resources