Skip to content
This repository was archived by the owner on Nov 19, 2021. It is now read-only.

Commit a47f3d0

Browse files
committed
Merge branch 'dev'
2 parents d35b5f9 + fd0eb80 commit a47f3d0

34 files changed

+496
-76
lines changed

Gruntfile.js

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module.exports = function(grunt) {
3333
var ia_page_js = [
3434
'handlebars_tmp',
3535
'DDH.js',
36+
'IADevPipeline.js',
3637
'IAIndex.js',
3738
'IAPage.js',
3839
'IAPageCommit.js',

lib/DDGC/DB/Result/Help.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ unique_column key => {
2424

2525
column help_category_id => {
2626
data_type => 'bigint',
27-
is_nullable => 0,
27+
is_nullable => 1,
2828
};
2929

30-
belongs_to 'help_category', 'DDGC::DB::Result::Help::Category', 'help_category_id';
30+
belongs_to 'help_category', 'DDGC::DB::Result::Help::Category', 'help_category_id', { join_type => 'left' };;
3131
sub category { shift->help_category(@_) }
3232

3333
column data => {

lib/DDGC/DB/Result/InstantAnswer/Topics.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ column topics_id => {
2121
primary_key (qw/instant_answer_id topics_id/);
2222

2323
belongs_to 'instant_answer', 'DDGC::DB::Result::InstantAnswer', 'instant_answer_id', {on_delete => 'cascade'};
24-
belongs_to 'topic', 'DDGC::DB::Result::Topic', 'topics_id';
24+
belongs_to 'topic', 'DDGC::DB::Result::Topic', 'topics_id', {on_delete => 'cascade'};
2525

2626
no Moose;
2727
__PACKAGE__->meta->make_immutable;

lib/DDGC/DB/Result/Topic.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ unique_column name => {
3030
is_nullable => 0,
3131
};
3232

33-
has_many 'instant_answer_topics', 'DDGC::DB::Result::InstantAnswer::Topics', 'topics_id';
33+
has_many 'instant_answer_topics', 'DDGC::DB::Result::InstantAnswer::Topics', 'topics_id', {on_delete => 'cascade'};
3434
many_to_many 'instant_answers', 'instant_answer_topics', 'instant_answer';
3535

3636
no Moose;

lib/DDGC/Web/Controller/Admin/Help.pm

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ sub index :Chained('base') :PathPart('') :Args(0) {
4646
if ($id > 0) {
4747
$help = $c->d->rs('Help')->find($id);
4848
die "help id ".$_." not found" unless $help;
49+
$help_values{help_category_id} ||= undef;
4950
for (keys %help_values) {
5051
$help->$_($help_values{$_});
5152
}

lib/DDGC/Web/Controller/InstantAnswer.pm

+141-32
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,37 @@ sub base :Chained('/base') :PathPart('ia') :CaptureArgs(0) {
1515
my ( $self, $c ) = @_;
1616
}
1717

18-
sub index :Chained('base') :PathPart('') :Args() {
19-
my ( $self, $c, $field, $value ) = @_;
18+
sub index :Chained('base') :PathPart('') :Args(0) {
19+
my ( $self, $c ) = @_;
2020
# Retrieve / stash all IAs for index page here?
2121

2222
# my @x = $c->d->rs('InstantAnswer')->all();
2323
# $c->stash->{ialist} = \@x;
2424
$c->stash->{ia_page} = "IAIndex";
2525

26-
if ($field && $value) {
27-
$c->stash->{field} = $field;
28-
$c->stash->{value} = $value;
29-
}
26+
#if ($field && $value) {
27+
# $c->stash->{field} = $field;
28+
# $c->stash->{value} = $value;
29+
#}
3030

3131
my $rs = $c->d->rs('Topic');
3232

3333
my @topics = $rs->search(
3434
{'name' => { '!=' => 'test' }},
3535
{
3636
columns => [ qw/ name id /],
37+
order_by => [ qw/ name /],
3738
result_class => 'DBIx::Class::ResultClass::HashRefInflator',
3839
}
3940
)->all;
4041

42+
my $is_admin;
43+
44+
if ($c->user) {
45+
$is_admin = $c->user->admin;
46+
}
47+
48+
$c->stash->{admin} = $is_admin;
4149
$c->stash->{title} = "Index: Instant Answers";
4250
$c->stash->{topic_list} = \@topics;
4351
$c->add_bc('Instant Answers', $c->chained_uri('InstantAnswer','index'));
@@ -46,18 +54,17 @@ sub index :Chained('base') :PathPart('') :Args() {
4654
}
4755

4856
sub ialist_json :Chained('base') :PathPart('json') :Args() {
49-
my ( $self, $c, $field, $value ) = @_;
50-
51-
my $rs;
57+
my ( $self, $c ) = @_;
5258

53-
if ($field && $value) {
54-
$rs = $c->d->rs('InstantAnswer')->search_rs({$field => $value});
55-
} else {
56-
$rs = $c->d->rs('InstantAnswer');
57-
}
59+
my $rs = $c->d->rs('InstantAnswer');
5860

5961
my @ial = $rs->search(
60-
{'topic.name' => { '!=' => 'test' }},
62+
{'topic.name' => { '!=' => 'test' },
63+
-or => [
64+
'me.dev_milestone' => { '=' => 'live'},
65+
'me.dev_milestone' => { '=' => 'ready'},
66+
],
67+
},
6168
{
6269
columns => [ qw/ name id repo src_name dev_milestone description template / ],
6370
prefetch => { instant_answer_topics => 'topic' },
@@ -104,7 +111,7 @@ sub iarepo_json :Chained('iarepo') :PathPart('json') :Args(0) {
104111

105112
my $src_options = $ia->src_options;
106113
if ($src_options ) {
107-
$iah{$ia->id}{src_options} = decode_json($src_options);
114+
$iah{$ia->id}{src_options} = from_json($src_options);
108115
}
109116

110117
$iah{$ia->id}{src_id} = $ia->src_id if $ia->src_id;
@@ -121,6 +128,70 @@ sub queries :Chained('base') :PathPart('queries') :Args(0) {
121128

122129
}
123130

131+
sub dev_pipeline_base :Chained('base') :PathPart('pipeline') :CaptureArgs(0) {
132+
my ( $self, $c ) = @_;
133+
}
134+
135+
sub dev_pipeline :Chained('dev_pipeline_base') :PathPart('') :Args(0) {
136+
my ( $self, $c ) = @_;
137+
138+
$c->stash->{ia_page} = "IADevPipeline";
139+
$c->stash->{title} = "Dev Pipeline";
140+
$c->add_bc('Instant Answers', $c->chained_uri('InstantAnswer','index'));
141+
$c->add_bc('Dev Pipeline', $c->chained_uri('InstantAnswer','dev_pipeline'));
142+
}
143+
144+
sub dev_pipeline_json :Chained('dev_pipeline_base') :PathPart('json') :Args(0) {
145+
my ( $self, $c ) = @_;
146+
147+
my $rs = $c->d->rs('InstantAnswer');
148+
my @planning = $rs->search(
149+
{'me.dev_milestone' => { '=' => 'planning'}},
150+
{
151+
columns => [ qw/ name id dev_milestone/ ],
152+
order_by => [ qw/ name/ ],
153+
result_class => 'DBIx::Class::ResultClass::HashRefInflator',
154+
}
155+
)->all;
156+
157+
my @in_development = $rs->search(
158+
{'me.dev_milestone' => { '=' => 'in_development'}},
159+
{
160+
columns => [ qw/ name id dev_milestone/ ],
161+
order_by => [ qw/ name/ ],
162+
result_class => 'DBIx::Class::ResultClass::HashRefInflator',
163+
}
164+
)->all;
165+
166+
my @qa = $rs->search(
167+
{'me.dev_milestone' => { '=' => 'qa'}},
168+
{
169+
columns => [ qw/ name id dev_milestone/ ],
170+
order_by => [ qw/ name/ ],
171+
result_class => 'DBIx::Class::ResultClass::HashRefInflator',
172+
}
173+
)->all;
174+
175+
my @ready = $rs->search(
176+
{'me.dev_milestone' => { '=' => 'ready'}},
177+
{
178+
columns => [ qw/ name id dev_milestone/ ],
179+
order_by => [ qw/ name/ ],
180+
result_class => 'DBIx::Class::ResultClass::HashRefInflator',
181+
}
182+
)->all;
183+
184+
$c->stash->{x} = {
185+
planning => \@planning,
186+
in_development => \@in_development,
187+
qa => \@qa,
188+
ready => \@ready,
189+
};
190+
191+
$c->stash->{not_last_url} = 1;
192+
$c->forward($c->view('JSON'));
193+
}
194+
124195
sub ia_base :Chained('base') :PathPart('view') :CaptureArgs(1) { # /ia/view/calculator
125196
my ( $self, $c, $answer_id ) = @_;
126197

@@ -196,20 +267,20 @@ sub ia_json :Chained('ia_base') :PathPart('json') :Args(0) {
196267
id => $issue->issue_id,
197268
title => $issue->title,
198269
body => $issue->body,
199-
tags => $issue->tags? decode_json($issue->tags) : undef
270+
tags => $issue->tags? from_json($issue->tags) : undef
200271
);
201272
} else {
202273
push(@ia_issues, {
203274
issue_id => $issue->issue_id,
204275
title => $issue->title,
205276
body => $issue->body,
206-
tags => $issue->tags? decode_json($issue->tags) : undef
277+
tags => $issue->tags? from_json($issue->tags) : undef
207278
});
208279
}
209280
}
210281
}
211282

212-
my $other_queries = $ia->other_queries? decode_json($ia->other_queries) : undef;
283+
my $other_queries = $ia->other_queries? from_json($ia->other_queries) : undef;
213284

214285
$ia_data{live} = {
215286
id => $ia->id,
@@ -222,9 +293,9 @@ sub ia_json :Chained('ia_base') :PathPart('json') :Args(0) {
222293
perl_module => $ia->perl_module,
223294
example_query => $ia->example_query,
224295
other_queries => $other_queries,
225-
code => $ia->code? decode_json($ia->code) : undef,
296+
code => $ia->code? from_json($ia->code) : undef,
226297
topic => \@topics,
227-
attribution => $ia->attribution? decode_json($ia->attribution) : undef,
298+
attribution => $ia->attribution? from_json($ia->attribution) : undef,
228299
issues => \@ia_issues,
229300
pr => \%pull_request,
230301
template => $ia->template,
@@ -233,8 +304,8 @@ sub ia_json :Chained('ia_base') :PathPart('json') :Args(0) {
233304
producer => $ia->producer,
234305
designer => $ia->designer,
235306
developer => $ia->developer,
236-
perl_dependencies => $ia->perl_dependencies? decode_json($ia->perl_dependencies) : undef,
237-
triggers => $ia->triggers? decode_json($ia->triggers) : undef,
307+
perl_dependencies => $ia->perl_dependencies? from_json($ia->perl_dependencies) : undef,
308+
triggers => $ia->triggers? from_json($ia->triggers) : undef,
238309
code_review => $ia->code_review,
239310
design_review => $ia->design_review,
240311
test_machine => $ia->test_machine,
@@ -310,7 +381,7 @@ sub commit_json :Chained('commit_base') :PathPart('json') :Args(0) {
310381
status => $ia->status,
311382
topic => \@topics,
312383
example_query => $ia->example_query,
313-
other_queries => $ia->other_queries? decode_json($ia->other_queries) : undef,
384+
other_queries => $ia->other_queries? from_json($ia->other_queries) : undef,
314385
dev_milestone => $ia->dev_milestone
315386
);
316387

@@ -336,7 +407,7 @@ sub commit_save :Chained('commit_base') :PathPart('save') :Args(0) {
336407

337408
if ($is_admin) {
338409
my $ia = $c->d->rs('InstantAnswer')->find($c->req->params->{id});
339-
my @params = decode_json($c->req->params->{values});
410+
my @params = from_json($c->req->params->{values});
340411

341412
for my $param (@params) {
342413
for my $hash_param (@{$param}) {
@@ -368,7 +439,7 @@ sub commit_save :Chained('commit_base') :PathPart('save') :Args(0) {
368439
}
369440
} else {
370441
if ($field eq 'other_queries') {
371-
$value = encode_json($value);
442+
$value = to_json($value);
372443
}
373444

374445
try {
@@ -412,7 +483,7 @@ sub save_edit :Chained('base') :PathPart('save') :Args(0) {
412483
my $autocommit = $c->req->params->{autocommit};
413484
if ($autocommit) {
414485
if ($field eq "topic") {
415-
my @topic_values = $value? decode_json($value) : undef;
486+
my @topic_values = $value? from_json($value) : undef;
416487
$ia->instant_answer_topics->delete;
417488

418489
for my $topic (@{$topic_values[0]}) {
@@ -475,6 +546,44 @@ sub save_edit :Chained('base') :PathPart('save') :Args(0) {
475546
return $c->forward($c->view('JSON'));
476547
}
477548

549+
sub create_ia :Chained('base') :PathPart('create') :Args() {
550+
my ( $self, $c ) = @_;
551+
552+
my $ia = $c->d->rs('InstantAnswer')->find({lc id => $c->req->params->{id}});
553+
my $is_admin;
554+
my $result = '';
555+
556+
if ($c->user && (!$ia)) {
557+
$is_admin = $c->user->admin;
558+
559+
if ($is_admin) {
560+
my $dev_milestone = $c->req->params->{dev_milestone};
561+
my $status = $dev_milestone;
562+
563+
if ($dev_milestone eq 'in_development') {
564+
$status =~ s/_/ /g;
565+
}
566+
567+
my $new_ia = $c->d->rs('InstantAnswer')->create({
568+
lc id => $c->req->params->{id},
569+
name => $c->req->params->{name},
570+
status => $status,
571+
dev_milestone => $dev_milestone,
572+
description => $c->req->params->{description},
573+
});
574+
575+
$result = 1;
576+
}
577+
}
578+
579+
$c->stash->{x} = {
580+
result => $result,
581+
};
582+
583+
$c->stash->{not_last_url} = 1;
584+
return $c->forward($c->view('JSON'));
585+
}
586+
478587
# Return a hash with the latest edits for the given IA
479588
sub current_ia {
480589
my ($d, $ia) = @_;
@@ -502,14 +611,14 @@ sub current_ia {
502611
# to see if this field was edited
503612
my %other_q = (
504613
edited => $other_q_edited,
505-
value => $other_q_val? decode_json($other_q_val) : undef
614+
value => $other_q_val? from_json($other_q_val) : undef
506615
);
507616

508617
%x = (
509618
name => $name[0][@name]{'value'},
510619
description => $desc[0][@desc]{'value'},
511620
status => $status[0][@status]{'value'},
512-
topic => $topic_val? decode_json($topic_val) : undef,
621+
topic => $topic_val? from_json($topic_val) : undef,
513622
example_query => $example_query[0][@example_query]{'value'},
514623
other_queries => \%other_q,
515624
dev_milestone => $dev_milestone[0][@dev_milestone]{'value'}
@@ -529,7 +638,7 @@ sub add_edit {
529638
my $current_updates = $ia->get_column('updates') || ();
530639

531640
if($value ne $orig_data){
532-
$current_updates = $current_updates? decode_json($current_updates) : undef;
641+
$current_updates = $current_updates? from_json($current_updates) : undef;
533642
my @field_updates = $current_updates->{$field}? $current_updates->{$field} : undef;
534643
my $time = time;
535644
my %new_update = ( value => $value,
@@ -560,7 +669,7 @@ sub remove_edit {
560669

561670
my $updates = ();
562671
my $column_updates = $ia->get_column('updates');
563-
my $edits = $column_updates? decode_json($column_updates) : undef;
672+
my $edits = $column_updates? from_json($column_updates) : undef;
564673
$edits->{$field} = undef;
565674

566675
$ia->update({updates => $edits});
@@ -586,7 +695,7 @@ sub get_edits {
586695

587696
try{
588697
my $column_updates = $ia_result->get_column('updates');
589-
$edits = $column_updates? decode_json($column_updates) : undef;
698+
$edits = $column_updates? from_json($column_updates) : undef;
590699
}catch{
591700
return;
592701
};

lib/DDGC/Web/Controller/Translate.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ sub token :Chained('logged_in') :Args(1) {
7272

7373
for (keys %{$c->req->params}) {
7474
if ($_ =~ m/token_notes_(\d+)_edit$/) {
75-
my $token = $c->d->resultset('Token')->find($_);
75+
my $token = $c->d->resultset('Token')->find($1);
7676
$token->notes($c->req->params->{$_});
7777
$token->update;
7878
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ddg_community_platform",
3-
"version": "0.56.0",
3+
"version": "0.57.0",
44
"engines": {
55
"node": ">=0.10.0"
66
},

root/static/css/ddgc0.56.0.css

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

root/static/css/ia0.56.0.css

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)