Skip to content

Commit

Permalink
kneb - 0.212
Browse files Browse the repository at this point in the history
  • Loading branch information
pbberlin committed Jan 8, 2024
1 parent de2a40c commit 5461641
Show file tree
Hide file tree
Showing 14 changed files with 201 additions and 28 deletions.
3 changes: 0 additions & 3 deletions app-bucket/content/kneb1/echart/inner-0.html
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,6 @@
const nameInstance0 = `${core}_0`;
const el0 = document.getElementById(nameInstance0);
if (el0) {
toolHeadline.innerHTML = `
Probieren Sie gerne das Tool selbst aus.
`;
toolHeadline.innerHTML = `
Probieren Sie die interaktive Graphik selbst aus.
`;
Expand Down
5 changes: 0 additions & 5 deletions app-bucket/content/kneb1/echart/inner-1.html
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,8 @@
const nameInstance0 = `${core}_0`;
const el0 = document.getElementById(nameInstance0);
if (el0) {
toolHeadline.innerHTML = `
Probieren Sie gerne das Tool selbst aus.
Welche Werte würden Sie für sich selbst wählen?
`;
toolHeadline.innerHTML = `
Probieren Sie die interaktive Graphik selbst aus.
Welche Werte würden Sie für sich selbst wählen?
`;
return el0
}
Expand Down
Binary file modified app-bucket/content/kneb1/slide-show/out/fin/00.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app-bucket/content/kneb1/slide-show/out/fin/01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app-bucket/content/kneb1/slide-show/out/fin/03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app-bucket/content/kneb1/slide-show/out/fin/04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app-bucket/content/kneb1/slide-show/out/fin/05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app-bucket/content/kneb1/slide-show/out/fin/06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/alexedwards/scs/redisstore v0.0.0-20231113091146-cef4b05350c8
github.com/alexedwards/scs/v2 v2.7.0
github.com/go-playground/form/v4 v4.2.1
github.com/go-stack/stack v1.8.1 // indirect
github.com/go-stack/stack v1.8.1
github.com/gomodule/redigo v1.8.9
github.com/google/martian v2.1.1-0.20190517191504-25dcb96d9e51+incompatible // indirect
github.com/pbberlin/dbg v1.0.3
Expand Down
9 changes: 7 additions & 2 deletions pkg/handlers/unsubscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"time"

"github.com/go-playground/form/v4"
"github.com/pbberlin/dbg"
"github.com/zew/go-questionnaire/pkg/cfg"
)

Expand Down Expand Up @@ -43,6 +42,8 @@ type unsubscribeT struct {
Task string `json:"task"`
Email string `json:"email"`
Date string `json:"date"`
URL1 string `json:"url1"` // the original URL raw query
URL2 string `json:"url2"` // the original URL query string

Response template.HTML `json:"response"`
}
Expand All @@ -54,6 +55,7 @@ func (us unsubscribeT) String() string {
fmt.Fprintf(b, "Email: %v\n", us.Email)
fmt.Fprintf(b, "Date: %v\n", us.Date)
fmt.Fprintf(b, "Response: %v\n", us.Response)
fmt.Fprintf(b, "URLs: %v - %v\n", us.URL1, us.URL2)
return b.String()
}
func (us unsubscribeT) CSVHeader() string {
Expand Down Expand Up @@ -191,9 +193,12 @@ func UnsubscribeH(w http.ResponseWriter, r *http.Request) {
fe.Response += template.HTML(msg + "<br>")
}

dbg.Dump(fe)
// dbg.Dump(fe)

// no errors
if fe.Response == "" {
fe.URL1 = r.RequestURI
fe.URL2 = r.URL.RawQuery
msg1, err := saveCSVRow(fe)
if err != nil {
fe.Response += template.HTML(err.Error() + "<br>")
Expand Down
75 changes: 59 additions & 16 deletions pkg/qst/funcs-dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package qst
import (
"fmt"
"log"
"net/http"
"strings"
"time"

Expand Down Expand Up @@ -355,33 +356,75 @@ func knebDownloadURL(q *QuestionnaireT, inp *inputT, paramSet string) (string, e

}

// URL to panel provider for payment
func knebLinkBackToPanel(q *QuestionnaireT, inp *inputT, paramSet string) (string, error) {
func doRequest(url string) (int, error) {

ret := ""
client := &http.Client{
// CheckRedirect: redirectPolicyFunc,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
log.Printf(" redirect #%v %v", len(via), req.URL.String())
// return http.ErrUseLastResponse
return nil
},
}

if val, ok := q.Attrs["i_survey"]; ok {
url := fmt.Sprintf(`https://www.gimpulse.com/?m=6006&return=complete&i_survey=%v`, val)
ret += fmt.Sprintf(`
<a href='%v' target='_blank' >Link back to GIM Panel for payment</a> <br>
%v <br>
resp, err := client.Get(url)
if err != nil {
return resp.StatusCode, err
}

if resp.StatusCode != http.StatusOK {
return resp.StatusCode, fmt.Errorf("panel server returned %v - %v", resp.Status, resp.StatusCode)
}

return http.StatusOK, nil
}

func helper(url, panelName string) string {

status, err := doRequest(url)
if err != nil {
log.Printf("%v panel returned %v - %v for %v", panelName, status, err, url)
return fmt.Sprintf(`
<a href='%v' target='_blank' >Bitte betätigen Sie den Link zum Panel %v für Ihre Auszahlung</a> <br>
<small>%v</small><br>
<br>
<small>Automatic submission - %v</small><br>
`,
url,
panelName,
url,
err,
)
}

return fmt.Sprintf(`
Der Panel %v wurde über die erfolgreiche Teilnahme informiert und hat die Information bestätigt.<br>
<small>%v</small><br>
`,
panelName,
url,
)

}

// URL to panel provider for payment
func knebLinkBackToPanel(q *QuestionnaireT, inp *inputT, paramSet string) (string, error) {

if val, ok := q.Attrs["i_survey"]; ok {
url := fmt.Sprintf(`https://www.gimpulse.com/?m=6006&return=complete&i_survey=%v`, val)
return helper(url, "GIM"), nil
}

if val, ok := q.Attrs["respBack"]; ok {
url := fmt.Sprintf(`https://www.opensurvey.com/survey/1579439651/1704195870?respBack=%v&statusBack=1`, val)
ret += fmt.Sprintf(`
<a href='%v' target='_blank' >Link back to Open Panel for payment</a> <br>
%v <br>
`,
url,
url,
)
return helper(url, "Open Panel"), nil
}

return fmt.Sprintf("<p>%v</p>", ret), nil
return `Keine Panel Benutzer-ID vorhanden. Falls Sie von GIM oder Open Panel gekommen sind,
kontaktieren Sie <a href="mailto:Caroline.Knebel@zew.de">Frau Knebel</a>.
Notieren und übermitteln Sie an Frau Knebel ihre Teilnahme ID. <br>
Sie finden diese rechts oben im Menüpunkt "Benutzer - Abmelden" in den nachfolgenden runden Klammmern. <br>
`, nil

}
2 changes: 1 addition & 1 deletion pkg/trl/hyphenization.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func init() {
func HyphenizeText(s string) string {

// we have to prevent hyphenization inside URL paths
if strings.Contains(s, "/") {
if false && strings.Contains(s, "/") {
return s
}

Expand Down
38 changes: 38 additions & 0 deletions pkg/trl/split-paths.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package trl

import (
"fmt"
"regexp"
"strings"
)

/*
https://regexr.com/
https://pkg.go.dev/regexp#Regexp.FindAllStringIndex
spaces some-path/to\directory whitespace
([\s]* ([\S]* [\\/] [\S]*) [\s]*)
condensed
([\S]*[\\/][\S]*)
*/
var pathToken = regexp.MustCompile(`[\S]*[\\/][\S]*`)
var _ = pathToken.FindAllStringIndex(`word <div style='font-size:90%' alt="attr" >div content</div> for/ward -and- back\ward eol`, -1)

// splitPaths returns [][]int{}
func splitPaths(re *regexp.Regexp, s string) [][]int {
return re.FindAllStringIndex(s, -1)
}

func recombine(s string, ps [][]int) string {
w := &strings.Builder{}
_ = w
prev := 0
for i := 0; i < len(ps); i++ {
occ := ps[i]
fmt.Fprint(w, s[prev:occ[0]])
fmt.Fprint(w, s[occ[0]:occ[1]])
}
return w.String()
}
95 changes: 95 additions & 0 deletions pkg/trl/split-paths_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package trl

import (
"fmt"
"log"
"reflect"
"regexp"
"testing"
)

var aAndPossiblyB = regexp.MustCompile(`ab?`)

func Test_splitPaths(t *testing.T) {
log.Printf("this test is temporary disabled")
return

type args struct {
s string
re *regexp.Regexp
}
tests := []struct {
name string
args args
want1 [][]int
want2 string
}{
{
name: "t1",
want1: [][]int{
{1, 3},
{10, 12},
{18, 19},
},
args: args{
// 012345678901234567890
// _ _ _ _ __
s: `tablett hablo espanol`,
re: aAndPossiblyB,
},
},
{
name: "t2",
want1: [][]int{
{6, 14},
},
args: args{
// 01234567890123456789
// _ _
s: `start for/ward stop`,
re: pathToken,
},
},
{
name: "t3",
want1: [][]int{
{48, 61},
{62, 70},
{77, 86},
},
args: args{
s: `word <div style='font-size:90%' alt="attr" >div content</div> for/ward -and- back\ward eol`,
re: pathToken,
},
},
}
for idx, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
nm := tt.name
if nm == "" {
nm = fmt.Sprintf("t%v", idx)
}
got1 := splitPaths(tt.args.re, tt.args.s)
if !reflect.DeepEqual(got1, tt.want1) {
t.Errorf("%10s - splitPaths() = \n\t got %v\n\t want %v",
nm,
got1,
tt.want1,
)
} else {
// t.Logf("%10s - is fine - %v", nm, got1)
}
got2 := recombine(tt.args.s, got1)
if !reflect.DeepEqual(got2, tt.args.s) {
t.Errorf("%10s - recombine() = \n\t got %v\n\t want %v",
nm,
got2,
tt.args.s,
)
} else {
// t.Logf("%10s - recombined to %s", nm, got2)
}
})
}

}

0 comments on commit 5461641

Please sign in to comment.