Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
c1b2ad8
temporary code for testing--will be removed before checkin
RichBCurious Mar 2, 2016
6a6d9dc
removed some print code that was used for debugging
RichBCurious Mar 8, 2016
93ddfd2
#867 added initial CustomLogin model object along with unit tests, wh…
RichBCurious Mar 7, 2016
f52ca6a
#867 filled out CustomLogin object, including cloning. Added a few mo…
RichBCurious Mar 7, 2016
63b6582
#867 added hasmany relationship with bookmarks and interest tags
RichBCurious Mar 7, 2016
fafe1c3
#867 added bookmark functionality to Entry along with a few tests
RichBCurious Mar 8, 2016
8a8811d
interem checking, starting to work on controller, but got switched to…
RichBCurious Mar 8, 2016
c4f14f5
fixed conflict of two people importing files around the same line of …
RichBCurious Mar 17, 2016
bc28b8b
re: #667 work in progress, Promo Code logic added to controller, alon…
RichBCurious Mar 24, 2016
6373587
#867 finished up promo code stuff: moved promocode logic to service; …
RichBCurious Mar 29, 2016
dc2af30
#867 added code to protect against null promo code stuff. Tutorial is…
RichBCurious Mar 29, 2016
21ff5d0
readding tests I had commented out. tweaked some other unit tests.
RichBCurious Mar 29, 2016
d8a4340
fixed register test to account for fact that it now returns parameters
RichBCurious Mar 29, 2016
b273b58
#867 had to uncomment some code I had commented out to ease debugging
RichBCurious Mar 29, 2016
c92fdc2
more risidual cleanup from rebase
RichBCurious Apr 21, 2016
dff058f
#867 finished tests and implementation of new promo code scheme, incl…
RichBCurious Apr 30, 2016
9a28232
removed an import line I no longer needed
RichBCurious Apr 30, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package us.wearecurio.controller
import grails.gsp.PageRenderer
import org.codehaus.groovy.grails.web.json.JSONObject
import us.wearecurio.model.Discussion
import us.wearecurio.model.InitialLoginConfiguration
import us.wearecurio.model.OAuthAccount
import us.wearecurio.model.User
import us.wearecurio.model.UserGroup
import us.wearecurio.services.DataService
import us.wearecurio.services.FitBitDataService
import us.wearecurio.services.UserRegistrationService
import us.wearecurio.services.JawboneService
import us.wearecurio.services.MovesDataService
import us.wearecurio.services.OuraDataService
Expand All @@ -26,6 +28,8 @@ class HomeController extends DataController {

static allowedMethods = [notifyJawbone: "POST", notifyfitbit: "POST"]

UserRegistrationService userRegistrationService

TwitterDataService twitterDataService
WithingsDataService withingsDataService
FitBitDataService fitBitDataService
Expand Down Expand Up @@ -519,9 +523,18 @@ class HomeController extends DataController {
}

def index() {
debug "HomeController.index()"
debug "HomeController.index() called with params: $params"
//**********************************************************************
//**********************************************************************
//********* REMOVE THIS LINE WHEN INTERESTS UI INCORPORATED **********
//********* THIS SETS DEFAULT INTEREST SUBJECT (preSelect==true)******
userRegistrationService.selectPromoCodeDefaults(sessionUser(), params?.promoCode)
//**********************************************************************
//**********************************************************************
def user = sessionUser()
[prefs:user.getPreferences(), showTime:params.showTime?:0, templateVer:urlService.template(request)]
[ prefs:user.getPreferences(),
showTime:params.showTime?:0, templateVer:urlService.template(request),
initialConfig:userRegistrationService.register(user, params?.promoCode).initialLoginConfig]
}

def load() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package us.wearecurio.controller
import grails.converters.JSON
import org.springframework.http.HttpStatus
//import us.wearecurio.model.InitialLoginConfiguration
import us.wearecurio.model.PasswordRecovery
import us.wearecurio.model.PushNotificationDevice
import us.wearecurio.model.Tag
import us.wearecurio.model.Entry
import us.wearecurio.model.User
import us.wearecurio.model.VerificationStatus
import us.wearecurio.services.EmailService
Expand Down Expand Up @@ -468,9 +471,33 @@ class LoginController extends SessionController {
if (p.metaTagName3 && p.metaTagValue3) {
user.addMetaTag(p.metaTagName3, p.metaTagValue3)
}

// String promo = p.promo_code?.trim()?.toLowerCase()
// InitialLoginConfiguration promoLogin
// if( promo != null && promo != "") {
// promoLogin = InitialLoginConfiguration.findByPromoCode(promo)
// if (promoLogin == null) {
// flash.message = "'$promo' is an invalid promo code"
// } else {
// flash.message = "registered with promo code:'$promo'"
// }
// } else {
// flash.message = "registered without promo code"
// }
// if (promoLogin == null) {
// promoLogin = InitialLoginConfiguration.defaultConfiguration()
// }
// promoLogin.interestTags?.each{user.addInterestTag(Tag.create(it))}
// promoLogin.bookmarks?.each{Entry.createBookmark(user.id,it)}
// params.initialConfig = promoLogin
params.promoCode = p.promo_code?.trim()?.toLowerCase()

setLoginUser(user)
execVerifyUser(user)
retVal['success'] = true
//retVal['initialConfig'] = promoLogin
//params.precontroller = "home"
//params.preaction = "sprint"
return retVal
}
}
Expand All @@ -484,9 +511,10 @@ class LoginController extends SessionController {
return
}
def retVal = execRegister(params)
debug "params: $params"
if (retVal['success']) {
session.showHelp = true
redirect(url:toUrl(controller: params.precontroller ?: 'home', action: params.preaction ?: 'index'))
redirect(url:toUrl(controller: params.precontroller ?: 'home', action: params.preaction ?: 'index', params: params))
} else if (retVal['errorCode'] == REGISTER_ERROR_USER_ALREADY_EXISTS) {
flash.message = "User " + params.username + " already exists"
redirect(url:toUrl(action:"register",
Expand Down
23 changes: 23 additions & 0 deletions grails-app/domain/us/wearecurio/model/Entry.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,29 @@ class Entry implements Comparable {
return e
}

public static Entry createBookmark(Long userId, String bookmarkText) {
return createBookmark(userId, bookmarkText, new Date())
}

public static Entry createBookmark(Long userId, String bookmarkText, Date baseDate) {
return createBookmark(userId, bookmarkText, baseDate, new EntryStats())
}

public static Entry createBookmark(Long userId, String bookmarkText, Date baseDate, EntryStats stats, EntryParserService entryParserService=null) {
return Entry.create(
userId,
(entryParserService==null?
EntryParserService.get():
entryParserService).parse(
baseDate,
"Etc/UTC",
bookmarkText,
RepeatType.CONTINUOUSGHOST.id,
null,
baseDate),
stats)
}

protected EntryGroup createOrFetchGroup() {
if (group != null) return group

Expand Down
117 changes: 117 additions & 0 deletions grails-app/domain/us/wearecurio/model/InitialLoginConfiguration.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package us.wearecurio.model

import groovy.transform.AutoClone

import us.wearecurio.model.TutorialInfo
import us.wearecurio.utility.Utils

class InitialLoginConfiguration {
static final String DEFAULT_PROMO_CODE = "default"

String promoCode

static hasMany = [interestAreas: InterestAreaBoolean]

TutorialInfo getTutorialInfo() {
TutorialInfo ret = TutorialInfo.findByName(promoCode)
if (ret == null) {
ret = TutorialInfo.defaultTutorialInfo()
}

return ret
}

List getInterestSubjects() {
List subjects = []
for (InterestAreaBoolean interest in interestAreas) {
for (InterestSubjectBoolean subject in interest.interest.interestSubjects) {
InterestSubjectBoolean matched = subjects.find{it.subject.name == subject.subject.name}
if (matched == null) {
subjects << new InterestSubjectBoolean(subject.subject, (interest.preSelect && subject.preSelect))
} else if (!matched.preSelect && interest.preSelect && subject.preSelect) {
matched.preSelect = true
}
}
}

return subjects
}

private setDefaults() {
InterestSubject subject = InterestSubject.createInterestSubject(
"sleep",
["sleep"],
["sleep 8 hours"],
"tags and bookmarks related to sleep",
true )
InterestArea interest = InterestArea.create()
interest.name = "sleep"
interest.addToInterestSubjects(new InterestSubjectBoolean(subject, true))
Utils.save(interest,true)
addToInterestAreas(new InterestAreaBoolean(interest,true))
}

static copy(InitialLoginConfiguration from, InitialLoginConfiguration to) {
if (from.tutorialInfo.name == TutorialInfo.DEFAULT_TUTORIAL) {
if (to.tutorialInfo.name != TutorialInfo.DEFAULT_TUTORIAL) {
to.tutorialInfo.delete()
}
} else {
if (to.tutorialInfo.name == TutorialInfo.DEFAULT_TUTORIAL) {
TutorialInfo newTI = new TutorialInfo()
newTI.name = to.promoCode
TutorialInfo.copy(from.tutorialInfo, newTI)
Utils.save(newTI,true)
} else {
TutorialInfo curTI = to.tutorialInfo
TutorialInfo.copy(from.tutorialInfo, curTI)
Utils.save(curTI,true)
}
}
from.interestAreas.each{
to.addToInterestAreas(new InterestAreaBoolean(it.interest, it.preSelect))
}
}

static InitialLoginConfiguration defaultConfiguration() {
InitialLoginConfiguration ret = InitialLoginConfiguration.findByPromoCode(DEFAULT_PROMO_CODE)

if (ret == null) {
ret = InitialLoginConfiguration.create()
ret.promoCode = DEFAULT_PROMO_CODE
ret.setDefaults()
Utils.save(ret, true)
}

return ret
}

static InitialLoginConfiguration createFromDefault() {
InitialLoginConfiguration ret = InitialLoginConfiguration.create()
ret.promoCode = ""

InitialLoginConfiguration d = defaultConfiguration()
if (d != null) {
copy(d, ret)
}

return ret
}

static InitialLoginConfiguration createFromDefault(String promoCode, Boolean save=false) {
InitialLoginConfiguration ret = createFromDefault()
if (ret != null) {
ret.promoCode = promoCode

if (save) {
Utils.save(ret, true)
}
}

return ret
}

static constraints = {
promoCode(maxSize:32, unique: true, blank:false, nullable:false)
}
}
9 changes: 9 additions & 0 deletions grails-app/domain/us/wearecurio/model/InterestArea.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package us.wearecurio.model

class InterestArea {
String name
static hasMany = [interestSubjects: InterestSubjectBoolean]
static constraints = {
name(maxSize:32, unique:true, blank:false, nullable:false)
}
}
16 changes: 16 additions & 0 deletions grails-app/domain/us/wearecurio/model/InterestAreaBoolean.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package us.wearecurio.model

//prefer to user Tuple2<InterestArea,Boolean>, but does not work in hasMany relationship
class InterestAreaBoolean {
InterestArea interest
Boolean preSelect

InterestAreaBoolean(InterestArea interest, Boolean preSelect) {
this.interest = interest
this.preSelect = preSelect
}

static constraints = {
preSelect(nullable:false)
}
}
56 changes: 56 additions & 0 deletions grails-app/domain/us/wearecurio/model/InterestSubject.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package us.wearecurio.model

import us.wearecurio.utility.Utils

class InterestSubject {
String name
String description

static hasMany = [interestTags: String, bookmarks: String]

static constraints = {
name(maxSize:32, unique:true, blank:false, nullable:false)
description(maxSize:128, unique:false, blank:true, nullable:true)
}

private InterestSubject(String name, String description, List interestTags, List bookmarks) {
this.name = name
this.description = description
interestTags.each {this.addToInterestTags(it)}
bookmarks.each {this.addToBookmarks(it)}
}

static List scrubList(List values) {
values.findAll{it != null && it.class == String && it != ""}
}

static InterestSubject createInterestSubject(
String name,
List interestTags,
List bookmarks,
String description="",
Boolean save=true
) {
if (name == null || name == "") {
return null
}

List tags = scrubList(interestTags)
List bkmarks = scrubList(bookmarks)
if (tags.size == 0 && bkmarks.size == 0) {
return null
}

if ( InterestSubject.findByName(name) != null ) {
return null
}

InterestSubject ret = new InterestSubject(name, description, tags, bkmarks)

if (save) {
Utils.save(ret, true)
}

return ret
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package us.wearecurio.model

//prefer to user Tuple2<InterestSubject,Boolean>, but does not work in hasMany relationship
class InterestSubjectBoolean {
Boolean preSelect
InterestSubject subject
InterestSubjectBoolean(InterestSubject subject, Boolean preSelect) {
this.preSelect = preSelect
this.subject = subject
}
static constraints = {
preSelect(nullable:false)
}
}
Loading