-Dserver.port.https=8443 dev run-app -https
Tuesday, September 12, 2017
Monday, August 28, 2017
Angular with tbSort AFTER loading of all ng-repeat
<!--class="{{{'cancelled': 'danger', 'closed': 'warning'}[sect.SECT_STATUS.toLowerCase()] || (((+sect.ENROLLED) >= (+sect.CAPACITY)) && 'warning')}}">-->
<tr ng-repeat="sect in crs.Sections" class="{{(!oldView) ? {'cancelled': 'danger', 'closed':
'warning'}[sect.SECT_STATUS.toLowerCase()] : ''}}">
<td style="vertical-align: middle" ng-repeat="col in cols" ng-if="!!allTitle || !col.hide || !col.hide(crs)" ng-bind-html="col.code(sect)"
class="media-middle {{(!oldView) ? 'highBorder' : 'highBorder'}}">
<!--{{($parent.$parent.$parent.$last &&
$parent.$parent.$last && $parent.$last && $last) &&
finish(sect)}}-->
<div ng-if="$parent.$parent.$parent.$last && $parent.$parent.$last && $parent.$last && $last">
<div ng-init="finish()"></div>
</div>
$scope.finish = function (it) {
// $scope.prnt($scope.curTerm + $scope.curSubj, true)
$scope.prnt('finish()')
if (!!$scope.wait || !$scope.loading) return
if (!!it) $scope.prnt(it)
// $('[data-toggle="tooltip"]').tooltip()
// $('[data-toggle="popover"]').popover()
$('.header').off('click').removeClass('header')
$('.tbSort').each(function () {
if ($(this).find('tr').length > 2) {
$(this).tablesorter()
}
})
// $scope.prnt($('.tbSort'))
$scope.loading = false
$scope.prnt('done')
}
Tuesday, August 22, 2017
Wednesday, August 16, 2017
Mapping a table or sequence to a schema
static mapping = { def cls = "admin" def appName = "see" table name: "${appName}_${cls}", schema: "NJITSRC" id column : "${cls}_id", generator : 'sequence', params: [sequence: "${appName}_${cls}_sequence", schema: "NJITSRC"]
Friday, August 11, 2017
Grails Export Plugin 1.5 Controller
def test = { params.exportFormat = 'pdf' params.format = 'pdf' params.extension = 'pdf' print params if(params?.exportFormat && params.exportFormat != "html"){ response.contentType = grailsApplication.config.grails.mime.types[params.exportFormat] response.setHeader("Content-disposition", "attachment; filename=hangtags.${params.extension}") List<String> fields = ['id', 'address'] Map labels = [address:"Address", deliverVia: ""] /* Formatter closure in previous releasesdef upperCase = { value -> return value.toUpperCase()}*/ // Formatter closure def upperCase = { domain, value -> return value.toUpperCase() } Map formatters = [address: upperCase] Map parameters = [title: "Hangtags", "column.widths": [0.2, 0.3, 0.5]] exportService.export(params.format, response.outputStream, HangTag.list(), fields, labels, formatters, parameters) [HangTag: HangTag.list()] } }
Front End Validation
1. If there is an ng-del checkbox newHt and existing hangtag
ng-disabled="(${hangTag ? true : false} && !newHt)"
Passing date from Oracle timestamp/ Grails backend to Javascript/ Angular controller
res.htDateDeliveredY = res.hangTag.dateDelivered.toString()[0..3].toInteger() res.htDateDeliveredM = (res.hangTag.dateDelivered.toString()[5..6]).toInteger() - 1res.htDateDeliveredD = res.hangTag.dateDelivered.toString()[8..9].toInteger()
$scope.htDateDelivered = new Date(${htDateDeliveredY},${htDateDeliveredM},${htDateDeliveredD})
OR
var dateDelivered = "${htDateDeliveredY}-${htDateDeliveredM}-${htDateDeliveredD}";document.getElementById("delDate").value = dateDelivered;console.log(dateDelivered);
Thursday, August 3, 2017
Domain Class
package main import grails.util.Holders /** * This domain class holds details (individual courses) of a request for combining 2 or more courses. * This domain class is used with "Request" domain class. * * READ DESCRIPTION IN "REQUEST" DOMAIN CLASS. * * !! RUN THE FOLLOWING LINE IN ORACLE DATABASE TO CREATE A SEQUENCE FOR THIS TABLE !! * CREATE SEQUENCE "NJIT_GNS"."LMIS_REQUESTINFO_SEQUENCE" MINVALUE 1 NOMAXVALUE INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE ; * * Columns: ( ** indicates "important". * indicates "not important but being used". nothing indicates "not being used") * "id" is a primary key and created by default * "version" is created by default * ** "req" is "Request" object to indicate this course belong to which request * ** "crn" is CRN of this course. "crn" and "term" together form a composite unique key * ** "term" is "Term" object to indicate this course belong to which term. "crn" and "term" together form a composite unique key * "schd_code" is "SCHD_CODE" of this course (e.g. 'LEC','ADV','LLB',etc.) * ** "active" is general column to indicate whether this course is active or inactive (inactive indicates this course is no longer a part of a combined course) * * "lastUpdated" is general column for datetime this data is last updated * * "updater" is general column for UCID of the person who updated this data */class RequestInfo { def springSecurityService String updater, crn, schd_code, section Boolean active Date lastUpdated Term term Request req static belongsTo = Request def beforeValidate = { // defaults active = (active == null) ? true : active updater = updater ?: springSecurityService.principal.usr.ucid } static mapping = { def cls = className.split('main.')[-1].toLowerCase() def appName = Holders.grailsApplication.config.app.name table "${appName}_${cls}" id column : "${cls}_reqinfoid", generator : 'sequence', params: [sequence: "${appName}_${cls}_sequence"] // version false version column : "${cls}_version", defaultValue: '0' req column : "${cls}_reqid" crn column : "${cls}_crn" section column : "${cls}_section" term column : "${cls}_term" schd_code column : "${cls}_schd_code" active column : "${cls}_is_active", defaultValue: '1' lastUpdated column : "${cls}_activity_date", defaultValue: 'sysdate' updater column : "${cls}_updated_by" } static constraints = { crn unique : 'term' crn size : 0..20 schd_code size : 0..3 updater maxSize : 10, matches: '[a-z0-9]+' section nullable: true } }
Multiple angular actions on ng click
ng-click="(vhc = ${vhc as grails.converters.JSON}) && (vhc.relate = '${vhc.relate.code}') && (vhcs.vhc_${vhc.id} = !vhcs.vhc_${vhc.id})">
Submit button (angular controller)
<button type="button" class="btn btn-success pull-right" ng-click="main.submitFrm(formRequest)" ng-init="formRequest.validate = validRegFrm" ng-disabled="!formRequest.validate(true)" disabled%{--ng-disabled="combineOK < 2 || !radio"--}% %{--ng-click="reqSubmit()" --}%> <i class="fa fa-check" aria-hidden="true"></i> Submit Combine Request </button>
Tuesday, August 1, 2017
Pass flashScope to webservice
mainService.saveNonNJITUser(user, WebUtils?.retrieveGrailsWebRequest()?.flashScope)
Redirect from action to another - with params
redirect(action: 'hangtagIndividual', params: [njitID: params.njitID, term: params.term])
Monday, July 31, 2017
Config values from DB
DATABASE
qry = """insert into NJITVRS_CONFIG (CONFIG_KEY, CONFIG_UPDATED_BY, CONFIG_VALUE) VALUES (?, '${usr}', ?)""".toString()
sql.executeInsert(qry, ['ht_comments', '[NR:"Not Recieved", L : "Lost", S : "Stolen", TC: "Type Change", REF: "Refund", DNP : "Do Not Process", DEL: "Deleted", RES:"Resigned", RET: "Returned Permit"]'])CONTROLLERhtComments : Eval.me(Config.findWhere(key: "ht_comments").value)FRONT END GSP<g:select from="${htComments}" noSelection="${['': 'Select']}" optionKey="key" optionValue="value" class="form-control" name="htComments" id="htComments" ng-model="htComments"></g:select>
Saving a GORM object
try { if (!term.save(flush: true)) { term.errors.allErrors.each { print it } flash << [success: false, message: 'Errors while changing term', obj: term] return } else { def oldTerms = Term.findAll() oldTerms = oldTerms.remove(Term.findIndexOf {term}) oldTerms.each { oldterm -> oldterm.active = false oldterm.save(flush: true) } flash << [success: true, message: 'Updated term successfully!'] } } catch (org.springframework.dao.DataIntegrityViolationException e) { flash << [success: false, message: 'Attempted duplicate term', obj: term] return false}
Thursday, October 27, 2016
Part 3 GORM
GORM
Domain classes are linked together through relationships; one-to-one, one-to-many, or many-to-many.
Each property is mapped to a
column in the database, where the convention for column names is all
lower case separated by underscores. For example
Domain classes are linked together through relationships; one-to-one, one-to-many, or many-to-many.
GORM is Grails' object relational
mapping (ORM) implementation. Under the hood it uses Hibernate 3.
CRUD
Create
def p = new Person(name: "Fred", age: 40, lastVisit: new Date()) p.save()
The save method will persist your class to the database using the underlying Hibernate ORM layer.
Read
Grails transparently adds an implicit
id property to your domain class which you can use for retrieval:def p = Person.get(1) assert 1 == p.id
Update
To update an instance, change some properties and then call save again:
def p = Person.get(1)
p.name = "Bob"
p.save()
Delete
To delete an instance use the delete method:
def p = Person.get(1) p.delete()
Domain Modelling in GORM
To create a domain class you run the create-domain-class command as follows:
grails create-domain-class org.bookstore.Book
The result will be a class at
grails-app/domain/org/bookstore/Book.groovy:package org.bookstoreclass Book { }
This class will map automatically to a table in the database called
book (the same name as the class). This behaviour is customizable through the ORM Domain Specific Language
Now that you have a domain class you can define its properties as Java types. For example:
package org.bookstoreclass Book { String title Date releaseDate String ISBN }
releaseDate maps onto a column release_date. Wednesday, October 19, 2016
Part 2: Configuration
PART 2: CONFIGURATION
A. DataSource.groovy
Unaltered in the VRS case study.
The
B. Introduction to BuildConfig.groovy and Config.groovy
where app.externPath is defined as:
2. Other Runtime Settings
D. Per Environment Configuration
A. DataSource.groovy
Unaltered in the VRS case study.
The
dbCreate property of the DataSource definition is important as it dictates what Grails should do at runtime with regards to automatically generating the database tables from GORM classes. The options are described in the DataSource section:createcreate-dropupdatevalidate- no value
B. Introduction to BuildConfig.groovy and Config.groovy
BuildConfig.groovy, is for settings that are used when running Grails commands, such as compile, doc, etc. The second file, Config.groovy, is for settings that are used when your application is running. This means that Config.groovy is packaged with your application, but BuildConfig.groovy is not.
When multiple settings have the same base, nesting, or partial nesting can be used:
app {
email {
host = 'mail.njit.edu' desc = desc
addr = 'vrs@njit.edu' err {
act = false to = usrs.dev
addr = 'Bugs <fix-it@njit.edu>'// view = '/error' }
}
}
Accessing settings from your own application:
1. The settings in BuildConfig.groovy are only available from command scripts and can be accessed via the grailsSettings.config property like so:
target(default: "Example command") {
def maxIterations = grailsSettings.config.myapp.iterations.max …}
2. For those defined in Config.groovy, use the grailsApplication object, which is available as a variable in controllers and tag libraries:
class MyController {
def hello() {
def recipient = grailsApplication.config.app.email.err.to
def recipient = grailsApplication.config.app.email.err.to
render "Hello ${recipient}"
}
}
}
}
C. Config.groovy
1. Externalised Configuration
grails.config.locations- The location of properties files or addition Grails Config files that should be merged with main configuration. e.g.
grails.config.locations = ["file:${app.externPath}"]
where app.externPath is defined as:
externPath = (!local) ? app_extern_config_path : 'target/extern/my_config.groovy'
2. Other Runtime Settings
grails.serverURL - A string specifying the server URL portion of absolute links, including server name e.g. grails.serverURL="http://my.yourportal.com"D. Per Environment Configuration
Grails supports the concept of per environment configuration. The
Config.groovy, DataSource.groovy, and BootStrap.groovy files in the grails-app/conf directory can use per-environment configuration using the syntax provided by ConfigSlurper. eg.:environments {
test {
app.email.err.act = true app.dataSrc.logSql = false }
production {
app.cas.url = 'https://webauth.njit.edu/idp/profile/cas' .
.
app.dataSrc.action = 'update' app.dataSrc.logSql = false }
}
There are 3 preset environments -
dev, prod, and test for development, production and test. For example to create a WAR for the test environment you wound run:
grails test war
Part1 : Introduction
Reference Documentation: http://docs.grails.org/2.3.8/guide/single.html#conf
Important sections:
1 <- does not mean whole section 1, it means read from 1 till 1.1 starts
2.[3,4,7,8,10,11] <- means 2.3, 2.4, 2.7, ...
4
4.1
4.1.1
4.2
4.3
4.3.[1,3,6] <- means 4.3.1, 4.3.3, ...
4.[4,5]
5
6
6.1
6.1.1
6.2
6.2.1
6.2.1.[1-4] <- means 6.2.1.1, 6.2.1.2, ..., 6.2.1.4
6.3
6.3.[1-5]
6.4
6.4.[1-5]
6.5
6.5.1
6.5.2
6.5.2.[1,4-9]
6.5.3
6.6
6.7
7
7.1
7.1.[1-4,6-9,11,12] - (7.1.6 (Intro), 7.1.7 (JSON))
7.2
7.2.1
7.2.1.[1,2,4]
7.2.2
7.2.2.[1-6]
7.2.[3,4]
7.3
7.3.[1-7]
7.4
7.4.[1,3,5,13]
7.6
7.6.[1-3]
8
8.2
10
10.[1,2,4,5]
11
11.1
11.1.1
11.[2-4]
13
13.[1-3]
14
14.[1-3]
14.5
14.5.1
17
19
Before creating Grails applications:
1. Download Grails framework (2.3.8), set GRAILS_HOME as a system variable, and add %GRAILS_HOME%\bin to your PATH. Set by step instructions can be found here.
-- Specific to case study VRS: add a system variable "local_machine" with the value of "1" or "true".
-- Specific to case study VRS: modify sample_my_config.groovy to my_config.groovy, change values as needed (banner tickets, usrname, pwd) and put in directory 'target/extern/my_config.groovy'.
Set up IDE (IntelliJ IDEA Ultimate for built in support).
3. Model - View - Controller Pattern
MVC pattern is a software architecture that encourages separation of concerns, such that:
Model - handles data representation and operations. For example, HangTag and Vehicle are part of the Model. Classes that represents entities (E.g. Vehicle) and business logic/functionalities (e.g. Register), collectively represent the model.
View - handles how data is viewed by the user. For example, the HTML code in register.gsp.
Controller - handle the code that links a user to the system. It receives request or events from the user, prepare data and invoke proper business logic, and then return the view that represents the result of user actions.
4. Grails uses Convention over Configuration, which means name and location of files is used instead of configuration, therefor it is important to be familiar with the directory structure:
Important sections:
1 <- does not mean whole section 1, it means read from 1 till 1.1 starts
2.[3,4,7,8,10,11] <- means 2.3, 2.4, 2.7, ...
4
4.1
4.1.1
4.2
4.3
4.3.[1,3,6] <- means 4.3.1, 4.3.3, ...
4.[4,5]
5
6
6.1
6.1.1
6.2
6.2.1
6.2.1.[1-4] <- means 6.2.1.1, 6.2.1.2, ..., 6.2.1.4
6.3
6.3.[1-5]
6.4
6.4.[1-5]
6.5
6.5.1
6.5.2
6.5.2.[1,4-9]
6.5.3
6.6
6.7
7
7.1
7.1.[1-4,6-9,11,12] - (7.1.6 (Intro), 7.1.7 (JSON))
7.2
7.2.1
7.2.1.[1,2,4]
7.2.2
7.2.2.[1-6]
7.2.[3,4]
7.3
7.3.[1-7]
7.4
7.4.[1,3,5,13]
7.6
7.6.[1-3]
8
8.2
10
10.[1,2,4,5]
11
11.1
11.1.1
11.[2-4]
13
13.[1-3]
14
14.[1-3]
14.5
14.5.1
17
19
Before creating Grails applications:
1. Download Grails framework (2.3.8), set GRAILS_HOME as a system variable, and add %GRAILS_HOME%\bin to your PATH. Set by step instructions can be found here.
-- Specific to case study VRS: add a system variable "local_machine" with the value of "1" or "true".
-- Specific to case study VRS: modify sample_my_config.groovy to my_config.groovy, change values as needed (banner tickets, usrname, pwd) and put in directory 'target/extern/my_config.groovy'.
Set up IDE (IntelliJ IDEA Ultimate for built in support).
2. Grails is a full stack framework and attempts to solve as many pieces of the web development puzzle through the core technology and its associated plugins. Included out the box are things like:
- An easy to use Object Relational Mapping (ORM) layer built on Hibernate
- An expressive view technology called Groovy Server Pages (GSP)
- A controller layer built on Spring MVC
- A command line scripting environment built on the Groovy-powered Gant
- An embedded Tomcat container which is configured for on the fly reloading
- Dependency injection with the inbuilt Spring container
- Support for internationalization (i18n) built on Spring's core MessageSource concept
- A transactional service layer built on Spring's transaction abstraction
3. Model - View - Controller Pattern
MVC pattern is a software architecture that encourages separation of concerns, such that:
Model - handles data representation and operations. For example, HangTag and Vehicle are part of the Model. Classes that represents entities (E.g. Vehicle) and business logic/functionalities (e.g. Register), collectively represent the model.
View - handles how data is viewed by the user. For example, the HTML code in register.gsp.
Controller - handle the code that links a user to the system. It receives request or events from the user, prepare data and invoke proper business logic, and then return the view that represents the result of user actions.
4. Grails uses Convention over Configuration, which means name and location of files is used instead of configuration, therefor it is important to be familiar with the directory structure:
grails-app- top level directory for Groovy sourcesconf- Configuration sources.controllers- Web controllers - The C in MVC.domain- The application domain.i18n- Support for internationalization (i18n).services- The service layer.taglib- Tag libraries.utils- Grails specific utilities.views- Groovy Server Pages - The V in MVC.scripts- Gant scripts.src- Supporting sourcesgroovy- Other Groovy sourcesjava- Other Java sourcestest- Unit and integration tests.
5. Deploying an application
Grails applications are deployed as Web Application Archives (WAR files), and Grails includes the war command for performing this task (runs in the
production environment by default):grails war
This will produce a WAR file under the
target directory which can then be deployed as per your container's instructions.
Subscribe to:
Posts (Atom)