Skip to content

Commit

Permalink
Several changes:
Browse files Browse the repository at this point in the history
 - Wt 4 specific:
  - Fixed regression introduced by adding msecsToHMS
  - Make sure that slots attached during signal emit are not executed immediately

    This fixes an issue where signals would loop infinitely, because the
    adding of a slot caused the same slot to be added again, etc.

    (modelReset() signal when calling e.g. clear() on a WStandardItemModel)
 - Merges from master:
  - Added a small clarification to WText intro about how invalid XHTML causes WText to switch to PlainText mode
  - CORS: only allow for WidgetSet, and allowed origins
    Introduced <allowed-origins> configuration option:
     - empty for no allowed origins
     - * for all
     - comma-separated list for exact matching
  - Added timeout handling to Postgres connections
  - fix dbo potential _unwind_resume problem with non-std::exception
  - make jwt resources-serving dependent on servlet version:
             v < 3: application server serves wt-resources
             v >= 3: servlet serves the wt-resources
  - fix ability to deploy same resource on multiple urls
  - added auxId() needed for e.g. sharding using Citus
  - Issue #5770: always render WAxisSliderWidget after WCartesianChart
   - Fix race condition related to detectDisconnect:
      Issue reported by Bruce Toll.
      We need to make sure to change disconnectCallback_ on the connection's
      strand, and we don't need an extra buffer to detect disconnect.
      Added test case written by Bruce Toll to check this race condition.
   - Handling NaN in maxZoom(), possible if using an empty series
   - Implement missing modelReset() in proxy models
     Issue raised by PR #118 on GitHub.
  • Loading branch information
RockinRoel committed Jul 26, 2017
1 parent fef7330 commit 1e4ed28
Show file tree
Hide file tree
Showing 45 changed files with 806 additions and 120 deletions.
4 changes: 2 additions & 2 deletions src/Wt/Chart/WAxis.C
Expand Up @@ -1282,10 +1282,10 @@ double WAxis::maxZoom() const
double min = drawnMinimum();
double max = drawnMaximum();
double zoom = (max - min) / minimumZoomRange();
if (zoom < 1.0)
if (zoom < 1.0 || zoom != zoom)
return 1.0;
else
return (max - min) / minimumZoomRange();
return zoom;
}

void WAxis::setMinimumZoomRange(double size)
Expand Down
9 changes: 4 additions & 5 deletions src/Wt/Chart/WAxisSliderWidget.C
Expand Up @@ -213,15 +213,14 @@ WTransform WAxisSliderWidget::hv(const WTransform& t) const

void WAxisSliderWidget::paintEvent(WPaintDevice *paintDevice)
{
// Don't paint anything, unless we're associated to a chart,
// and the chart has been painted.
if (chart() && !chart()->cObjCreated_) {
return;
}
if (!chart()) {
LOG_ERROR("Attempted to draw a slider widget not associated with a chart.");
return;
}
// Don't paint anything, unless we're associated to a chart,
// and the chart has been painted.
if (!chart()->cObjCreated_ || chart()->needRerender())
return;

if (series_->type() != SeriesType::Line &&
series_->type() != SeriesType::Curve) {
Expand Down
2 changes: 2 additions & 0 deletions src/Wt/Chart/WCartesianChart
Expand Up @@ -1290,6 +1290,8 @@ private:

static WColor lightenColor(const WColor &in);

virtual void getDomChanges(std::vector<DomElement *>& result, WApplication *app) override;

protected:
virtual void modelChanged() override;
virtual void modelReset() override;
Expand Down
10 changes: 7 additions & 3 deletions src/Wt/Chart/WCartesianChart.C
Expand Up @@ -2383,10 +2383,14 @@ void WCartesianChart::paintEvent(WPaintDevice *paintDevice)
doJavaScript(ss.str());

cObjCreated_ = true;
}
}

for (std::size_t i = 0; i < axisSliderWidgets_.size(); ++i) {
axisSliderWidgets_[i]->update();
}
void WCartesianChart::getDomChanges(std::vector<DomElement *>& result, WApplication *app)
{
WAbstractChart::getDomChanges(result, app);
for (std::size_t i = 0; i < axisSliderWidgets_.size(); ++i) {
axisSliderWidgets_[i]->update();
}
}

Expand Down
13 changes: 11 additions & 2 deletions src/Wt/Dbo/DbAction
Expand Up @@ -61,7 +61,7 @@ private:

bool idField_;
std::string foreignKeyTable_, foreignKeyName_;
int fkConstraints_;
int fkConstraints_, fkFlags_;
};

class WTDBO_API DropSchema
Expand Down Expand Up @@ -174,14 +174,19 @@ public:
* to simply bind values to a statement using field().
*/
SaveBaseAction(Session *session, SqlStatement *statement, int column);

SaveBaseAction(MetaDboBase& dbo, Impl::MappingInfo& mapping,
SqlStatement *statement = nullptr, int column = 0);

template<typename V> void act(const FieldRef<V>& field);
template<class C> void actPtr(const PtrRef<C>& field);
template<class C> void actWeakPtr(const WeakPtrRef<C>& field);
template<class C> void actCollection(const CollectionRef<C>& field);
template<typename V> void actId(V& value, const std::string& name, int size);
template<class D> void actId(ptr<D>& value, const std::string& name, int size,
int fkConstraints);

template<class C> void visitAuxIds(C& obj);

bool getsValue() const;

Expand All @@ -192,6 +197,7 @@ protected:
bool isInsert_;
int column_;
bool bindNull_;
bool auxIdOnly_;

enum { Dependencies, Self, Sets } pass_;
bool needSetsPass_;
Expand Down Expand Up @@ -358,6 +364,9 @@ struct action_sets_value<FromAnyAction> : std::true_type { };
template<typename V>
void SaveBaseAction::act(const FieldRef<V>& field)
{
if (auxIdOnly_ && !(field.flags() & FieldRef<V>::AuxId))
return;

if (pass_ == Self) {
if (bindNull_)
statement_->bindNull(column_++);
Expand Down
9 changes: 6 additions & 3 deletions src/Wt/Dbo/DbAction.C
Expand Up @@ -32,7 +32,8 @@ namespace Wt {
InitSchema::InitSchema(Session& session, Impl::MappingInfo& mapping)
: session_(session),
mapping_(mapping),
idField_(false)
idField_(false),
fkFlags_(0)
{ }

void InitSchema::actMapping(Impl::MappingInfo *mapping)
Expand Down Expand Up @@ -125,7 +126,8 @@ SaveBaseAction::SaveBaseAction(Session *session, SqlStatement *statement,
: DboAction(session),
statement_(statement),
column_(column),
bindNull_(false)
bindNull_(false),
auxIdOnly_(false)
{
pass_ = Self;
}
Expand All @@ -135,7 +137,8 @@ SaveBaseAction::SaveBaseAction(MetaDboBase& dbo, Impl::MappingInfo& mapping,
: DboAction(dbo, mapping),
statement_(statement),
column_(column),
bindNull_(false)
bindNull_(false),
auxIdOnly_(false)
{
pass_ = Self;
}
Expand Down
49 changes: 45 additions & 4 deletions src/Wt/Dbo/DbAction_impl.h
Expand Up @@ -81,6 +81,9 @@ void InitSchema::act(const FieldRef<V>& field)
if (idField_)
flags |= FieldFlags::NaturalId; // Natural id

if ((field.flags() & FieldRef<V>::AuxId) || (fkFlags_ & PtrRef<V>::AuxId))
flags |= FieldFlags::AuxId; // Aux id (appended in update and delete)

if (!foreignKeyName_.empty())
// Foreign key
mapping_.fields.push_back
Expand All @@ -104,6 +107,7 @@ void InitSchema::actPtr(const PtrRef<C>& field)
foreignKeyName_ = field.name();
foreignKeyTable_ = mapping->tableName;
fkConstraints_ = field.fkConstraints();
fkFlags_ = field.flags();
}

field.visit(*this, &session_);
Expand All @@ -112,6 +116,7 @@ void InitSchema::actPtr(const PtrRef<C>& field)
foreignKeyName_.clear();
foreignKeyTable_.clear();
fkConstraints_ = 0;
fkFlags_ = 0;
}
}

Expand Down Expand Up @@ -334,6 +339,28 @@ void LoadDbAction<C>::actId(ptr<D>& value, const std::string& name, int size,
* SaveDbAction
*/

template <class C>
void SaveBaseAction::visitAuxIds(C& obj)
{
auxIdOnly_ = true;
pass_ = Self;

persist<C>::apply(obj, *this);
}

template<typename V>
void SaveBaseAction::actId(V& value, const std::string& name, int size)
{
/* Only used from within visitAuxIds() */
}

template<class D>
void SaveBaseAction::actId(ptr<D>& value, const std::string& name, int size,
int fkConstraints)
{
/* Only used from within visitAuxIds() */
}

template<class C>
void SaveBaseAction::actPtr(const PtrRef<C>& field)
{
Expand All @@ -347,10 +374,18 @@ void SaveBaseAction::actPtr(const PtrRef<C>& field)

break;
case Self:
bindNull_ = !field.value();
field.visit(*this, session());
bindNull_ = false;
if (auxIdOnly_ && !(field.flags() & PtrRef<C>::AuxId))
return;

{
bool wasAuxIdOnly = auxIdOnly_;
auxIdOnly_ = false;
bindNull_ = !field.value();
field.visit(*this, session());
bindNull_ = false;
auxIdOnly_ = wasAuxIdOnly;
}

break;
case Sets:
break;
Expand All @@ -360,6 +395,9 @@ void SaveBaseAction::actPtr(const PtrRef<C>& field)
template<class C>
void SaveBaseAction::actWeakPtr(const WeakPtrRef<C>& field)
{
if (auxIdOnly_)
return;

switch (pass_) {
case Dependencies:
break;
Expand All @@ -377,6 +415,9 @@ void SaveBaseAction::actWeakPtr(const WeakPtrRef<C>& field)
template<class C>
void SaveBaseAction::actCollection(const CollectionRef<C>& field)
{
if (auxIdOnly_)
return;

switch (pass_) {
case Dependencies:
break;
Expand Down Expand Up @@ -499,7 +540,7 @@ void SaveDbAction<C>::visit(C& obj)

if (!isInsert_) {
MetaDboBase *dbo = dynamic_cast<MetaDboBase *>(&dbo_);
dbo->bindId(statement_, column_);
dbo->bindModifyId(statement_, column_);

if (mapping().versionFieldName) {
// when saved in the transaction, we will be at version() + 1
Expand Down
25 changes: 23 additions & 2 deletions src/Wt/Dbo/Field
Expand Up @@ -142,10 +142,15 @@ template <typename V>
class FieldRef
{
public:
FieldRef(V& value, const std::string& name, int size);
enum Flag {
AuxId = 0x1
};

FieldRef(V& value, const std::string& name, int size, int flags = 0);

const std::string& name() const;
int size() const;
int flags() const;

std::string sqlType(Session& session) const;
const std::type_info *type() const;
Expand All @@ -159,6 +164,7 @@ private:
V& value_;
std::string name_;
int size_;
int flags_;
};

/*! \brief Type of an SQL relation.
Expand Down Expand Up @@ -197,11 +203,16 @@ template <class C>
class PtrRef
{
public:
PtrRef(ptr<C>& value, const std::string& name, int fkConstraints);
enum Flag {
AuxId = 0x1
};

PtrRef(ptr<C>& value, const std::string& name, int fkConstraints, int flags = 0);

const std::string& name() const { return name_; }
bool literalForeignKey() const { return literalForeignKey_; }
int fkConstraints() const { return fkConstraints_; }
int flags() const { return flags_; }
ptr<C>& value() const { return value_; }
typename dbo_traits<C>::IdType id() const { return value_.id(); }

Expand All @@ -218,6 +229,7 @@ private:
std::string name_;
bool literalForeignKey_;
int fkConstraints_;
int flags_;
};

template <class C>
Expand Down Expand Up @@ -269,6 +281,15 @@ template <class Action, class C>
void id(Action& action, ptr<C>& value, const std::string& name,
ForeignKeyConstraint constraints, int size = -1);

template <class Action, typename V>
void auxId(Action& action, V& value, const std::string& name,
int size = -1);

template <class Action, class C>
void auxId(Action& action, ptr<C>& value, const std::string& name,
ForeignKeyConstraint constraint = ForeignKeyConstraint(0), int size = -1);


/*! \brief Maps a database object field.
*
* This function binds the field \p value to the database field \p name.
Expand Down
30 changes: 26 additions & 4 deletions src/Wt/Dbo/Field_impl.h
Expand Up @@ -17,10 +17,11 @@ namespace Wt {
namespace Dbo {

template <typename V>
FieldRef<V>::FieldRef(V& value, const std::string& name, int size)
FieldRef<V>::FieldRef(V& value, const std::string& name, int size, int flags)
: value_(value),
name_(name),
size_(size)
size_(size),
flags_(flags)
{ }

template <typename V>
Expand All @@ -35,6 +36,12 @@ int FieldRef<V>::size() const
return size_;
}

template <typename V>
int FieldRef<V>::flags() const
{
return flags_;
}

template <typename V>
std::string FieldRef<V>::sqlType(Session& session) const
{
Expand Down Expand Up @@ -81,11 +88,12 @@ CollectionRef<C>::CollectionRef(collection< ptr<C> >& value,

template <class C>
PtrRef<C>::PtrRef(ptr<C>& value, const std::string& name,
int fkConstraints)
int fkConstraints, int flags)
: value_(value),
name_(name),
literalForeignKey_(false),
fkConstraints_(fkConstraints)
fkConstraints_(fkConstraints),
flags_(flags)
{
if (!name.empty() && name[0] == '>') {
name_ = std::string(name.c_str() + 1, name.size() - 1);
Expand Down Expand Up @@ -176,6 +184,20 @@ void id(A& action, ptr<C>& value, const std::string& name,
action.actId(value, name, size, constraint.value());
}

template <class Action, typename V>
void auxId(Action& action, V& value, const std::string& name,
int size)
{
action.act(FieldRef<V>(value, name, size, FieldRef<V>::AuxId));
}

template <class Action, class C>
void auxId(Action& action, ptr<C>& value, const std::string& name,
ForeignKeyConstraint constraint, int size)
{
action.actPtr(PtrRef<C>(value, name, constraint.value(), PtrRef<C>::AuxId));
}

template <class A, typename V>
void field(A& action, V& value, const std::string& name, int size)
{
Expand Down
1 change: 1 addition & 0 deletions src/Wt/Dbo/QueryModel_impl.h
Expand Up @@ -286,6 +286,7 @@ void QueryModel<Result>::cacheRow(int row) const

Transaction transaction(query_.session());

std::cerr << "Fetching offset=" << qOffset << ", limit=" << qLimit << std::endl;
collection<Result> results = query_.resultList();
cache_.clear();
cache_.insert(cache_.end(), results.begin(), results.end());
Expand Down

0 comments on commit 1e4ed28

Please sign in to comment.