Skip to content

Commit

Permalink
Merge pull request #955 from crossroads/master
Browse files Browse the repository at this point in the history
[Release] Stock v0.20.8
  • Loading branch information
patrixr authored Dec 1, 2020
2 parents 85ce23f + 331db07 commit 55509e9
Show file tree
Hide file tree
Showing 55 changed files with 496 additions and 150 deletions.
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ GEM
json (>= 1.5.1)
atomos (0.1.3)
aws-eventstream (1.1.0)
aws-partitions (1.393.0)
aws-sdk-core (3.109.2)
aws-partitions (1.397.0)
aws-sdk-core (3.109.3)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.239.0)
aws-sigv4 (~> 1.1)
jmespath (~> 1.0)
aws-sdk-kms (1.39.0)
aws-sdk-core (~> 3, >= 3.109.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.84.1)
aws-sdk-s3 (1.85.0)
aws-sdk-core (~> 3, >= 3.109.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.1)
Expand Down Expand Up @@ -93,7 +93,7 @@ GEM
faraday_middleware (1.0.0)
faraday (~> 1.0)
fastimage (2.2.0)
fastlane (2.167.0)
fastlane (2.168.0)
CFPropertyList (>= 2.3, < 4.0.0)
addressable (>= 2.3, < 3.0.0)
aws-sdk-s3 (~> 1.0)
Expand Down
3 changes: 1 addition & 2 deletions app/components/contained-package.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Ember from "ember";
import ItemActionMixin from "stock/mixins/item_actions";

export default Ember.Component.extend(ItemActionMixin, {
export default Ember.Component.extend({
packageService: Ember.inject.service(),
store: Ember.inject.service(),

Expand Down
4 changes: 2 additions & 2 deletions app/components/date-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export default Ember.TextField.extend({

Ember.run.scheduleOnce("afterRender", this, function() {
Ember.$(this.element).pickadate({
selectMonths: !!enablePastDate,
selectYears: !!enablePastDate,
selectMonths: true,
selectYears: true,
formatSubmit: "ddd mmm d",
monthsFull: moment.months(),
monthsShort: moment.monthsShort(),
Expand Down
25 changes: 21 additions & 4 deletions app/components/focus-textfield.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Ember from "ember";
import { callbackObserver } from "../utils/ember";

export default Ember.TextField.extend({
tagName: "input",
Expand All @@ -7,19 +8,33 @@ export default Ember.TextField.extend({
cordova: Ember.inject.service(),
store: Ember.inject.service(),
hasRecentDesignations: true,
autofocus: true,
autofocusOnEmptyValue: true,

triggerAutofocus: Ember.observer("value", function() {
if (this.get("value").length === 0) {
this.$().focus();
valueAutofocusListener: Ember.observer("value", function() {
if (
this.get("autofocus") &&
this.get("autofocusOnEmptyValue") &&
this.get("value").length === 0
) {
this.applyFocus();
}
}),

autofocusSettingListener: callbackObserver("autofocus", [
[true, "applyFocus"]
]),

hasFixedInputHeader: Ember.computed(function() {
return (
this.get("cordova").isIOS() && Ember.$(".fixed_search_header").length > 0
);
}),

applyFocus() {
this.$().trigger("focus");
},

scrollToStart() {
Ember.$(".fixed_search_header").addClass("absolute");
Ember.$(".footer").addClass("absolute_footer");
Expand All @@ -38,7 +53,9 @@ export default Ember.TextField.extend({

didInsertElement() {
document.body.scrollTop = document.documentElement.scrollTop = 0;
this.$().focus();
if (this.get("autofocus")) {
this.applyFocus();
}
if (this.get("hasFixedInputHeader")) {
this.element.addEventListener("touchstart", this.scrollToStart);
}
Expand Down
10 changes: 9 additions & 1 deletion app/components/goodcity/code-search-overlay.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Ember from "ember";
import _ from "lodash";
import SearchMixin from "stock/mixins/search_resource";
import AsyncMixin, { ASYNC_BEHAVIOURS } from "stock/mixins/async";

/**
* An overlay that pops up from the bottom of the screen, allowing the user
Expand All @@ -11,8 +12,9 @@ import SearchMixin from "stock/mixins/search_resource";
* @property {boolean} open whether the popup is visible or not
* @property {function} onSelect callback triggered when an order is selected
*/
export default Ember.Component.extend(SearchMixin, {
export default Ember.Component.extend(SearchMixin, AsyncMixin, {
store: Ember.inject.service(),
packageTypeService: Ember.inject.service(),
filter: "",
searchText: "",
fetchMoreResult: true,
Expand All @@ -22,6 +24,12 @@ export default Ember.Component.extend(SearchMixin, {
this._super("code-search-overlay");
},

async didRender() {
await this.runTask(() => {
return this.get("packageTypeService").preload();
}, ASYNC_BEHAVIOURS.SILENT_DEPENDENCY);
},

allPackageTypes: Ember.computed("open", "subsetPackageTypes", function() {
if (this.get("subsetPackageTypes")) {
return this.get("subsetPackageTypes");
Expand Down
30 changes: 30 additions & 0 deletions app/components/goodcity/item-search-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import _ from "lodash";
import config from "stock/config/environment";
import SearchMixin from "stock/mixins/search_resource";
import AsyncMixin from "stock/mixins/async";
import { chain } from "../../utils/async";
import { callbackObserver } from "../../utils/ember";

export default Ember.Component.extend(SearchMixin, AsyncMixin, {
searchText: "",
Expand All @@ -12,13 +14,27 @@ export default Ember.Component.extend(SearchMixin, AsyncMixin, {
perPage: 10,
isMobileApp: config.cordova.enabled,
packageService: Ember.inject.service(),
cordova: Ember.inject.service(),
messageBox: Ember.inject.service(),
i18n: Ember.inject.service(),
requireFocus: false,

inputmode: Ember.computed("searchMode", function() {
if (this.get("searchMode") === "numeric") {
return "numeric";
}
return "text";
}),

hasSearchText: Ember.computed("searchText", function() {
return !!this.get("searchText");
}),

openStateListener: callbackObserver("open", [
[true, "onOpen"],
[false, "onClose"]
]),

closeOverlay() {
this.setProperties({
searchText: "",
Expand All @@ -38,6 +54,20 @@ export default Ember.Component.extend(SearchMixin, AsyncMixin, {
return _.flatten([states]).join(",");
},

async onOpen() {
const platform = this.get("cordova");
const scrollFix = platform.isIOS() || platform.isIOSBrowser();

await chain.stagerred([
() => this.set("requireFocus", true),
() => scrollFix && window.scrollTo(0, 0)
]);
},

onClose() {
this.set("requireFocus", false);
},

actions: {
cancel() {
this.closeOverlay();
Expand Down
2 changes: 1 addition & 1 deletion app/components/goodcity/offers-search-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default Ember.Component.extend(SearchMixin, {
companies: true,
slug: "search",
is_desc: true,
sort_column: "reviewed_at"
sort_column: "received_at"
},
this.get("offer_state"),
this.getSearchQuery(),
Expand Down
58 changes: 58 additions & 0 deletions app/components/goodcity/remove-item-from-container.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import Ember from "ember";
import _ from "lodash";
const { getOwner } = Ember;

import AsyncMixin, { ERROR_STRATEGIES } from "stock/mixins/async";
import ItemActions from "stock/mixins/item_actions";

export default Ember.Component.extend(AsyncMixin, ItemActions, {
packageService: Ember.inject.service(),
locationService: Ember.inject.service(),

isValidQuantity: Ember.computed(
"maxRemovableQuantity",
"removableQuantity",
function() {
let value = +this.get("removableQuantity");
return value > 0 && value <= +this.get("maxRemovableQuantity");
}
),

actions: {
async beginUnpack(container, item, quantity) {
this.set("openRemoveItemOverlay", false);

const selectedLocation = await this.get(
"locationService"
).userPickLocation();

if (!selectedLocation) {
return;
} else {
this.set("removableQuantity", quantity);
this.set("maxRemovableQuantity", quantity);

this.set("location", selectedLocation);
this.set("openRemoveItemOverlay", true);
}
},

async performUnpack() {
await this.runTask(() => {
return this.unpack(
this.get("container"),
this.get("item"),
this.get("location.id"),
this.get("removableQuantity"),
this.get("onUnpackCallback")
);
}, ERROR_STRATEGIES.MODAL);

this.set("openRemoveItemOverlay", false);
},

cancelAction() {
this.set("openRemoveItemOverlay", false);
}
}
});
5 changes: 5 additions & 0 deletions app/components/message-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export default Ember.Component.extend({
displayCloseLink: false,
isVisible: false,

init() {
this._super(...arguments);
this.get("router").addObserver("currentRouteName", () => this.close());
},

close() {
if (this.get("isVisible")) {
this.set("isVisible", false);
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/items/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,8 @@ export default GoodcityController.extend(
per_page: 10
})
.then(data => {
this.get("store").pushPayload(data);
return data;
this.set("containerQuantity", data.containerQuantity);
return data.containedPackages;
});
},

Expand Down
10 changes: 8 additions & 2 deletions app/controllers/stocktakes/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const SORTING = {
},
BY_INVENTORY_NUM: (rev1, rev2) => {
const [n1, n2] = [rev1, rev2]
.map(r => r.getWithDefault("item.inventoryNumber", "0"))
.map(r => r.get("item.inventoryNumber") || "0")
.map(inv => inv.replace(/[^0-9]/g, ""))
.map(Number);

Expand Down Expand Up @@ -254,7 +254,13 @@ export default Ember.Controller.extend(AsyncMixin, {
* @param {Package} pkg
*/
async addItem(pkg) {
pkg = pkg || (await this.get("packageService").userPickPackage());
this.stopScanning();

pkg =
pkg ||
(await this.get("packageService").userPickPackage({
searchMode: "numeric"
}));

if (!pkg) return;

Expand Down
57 changes: 39 additions & 18 deletions app/controllers/users/contact_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,39 @@ export default Ember.Controller.extend(
user: Ember.computed.alias("model.user"),
userService: Ember.inject.service(),

invalidEmail: Ember.computed("user.email", function() {
const emailRegEx = new RegExp(regex.EMAIL_REGEX);
return this.get("user.email").match(emailRegEx);
}),
isValidEmail(email) {
return regex.EMAIL_REGEX.test(email);
},

invalidMobile: Ember.computed("mobileNumber", function() {
const hkMobileNumberRegEx = new RegExp(regex.HK_MOBILE_NUMBER_REGEX);
return this.get("mobileNumber").match(hkMobileNumberRegEx);
}),
isValidMobile(mobile) {
return regex.HK_MOBILE_NUMBER_REGEX.test(mobile);
},

checkUserEmailValidity(email) {
if (email) {
return this.isValidEmail(email);
} else {
return (
this.get("user.disabled") ||
this.isValidMobile(this.get("mobileNumber"))
);
}
},

checkUserMobileValidity(mobile) {
if (mobile) {
return this.isValidMobile(mobile);
} else {
return (
this.get("user.disabled") || this.isValidEmail(this.get("user.email"))
);
}
},

hideValidationErrors(target) {
this.set(`${target.id}InputError`, false);
this.set(`${target.id}ValidationError`, false);
},

districts: Ember.computed(function() {
return this.get("store")
Expand All @@ -39,11 +63,12 @@ export default Ember.Controller.extend(
updateUserDetails(e) {
let value = e.target.value.trim();
let isValid;

if (Object.keys(this.get("user").changedAttributes()).length === 0) {
this.set(`${e.target.id}InputError`, false);
this.set(`${e.target.id}ValidationError`, false);
this.hideValidationErrors(e.target);
return;
}

switch (e.target.id) {
case "firstName":
isValid = Boolean(value);
Expand All @@ -52,24 +77,20 @@ export default Ember.Controller.extend(
isValid = Boolean(value);
break;
case "email":
isValid = value
? Boolean(this.get("invalidEmail"))
: Boolean(this.get("invalidMobile"));
isValid = this.checkUserEmailValidity(value);
break;
case "mobile":
isValid = value
? Boolean(this.get("invalidMobile"))
: Boolean(this.get("invalidEmail"));
isValid = this.checkUserMobileValidity(value);
break;
}

if (isValid) {
this.runTask(async () => {
let user = this.get("user");
value = e.target.id == "mobile" && value ? "+852" + value : value;
user.set(e.target.id, value);
await user.save();
this.set(`${e.target.id}InputError`, false);
this.set(`${e.target.id}ValidationError`, false);
this.hideValidationErrors(e.target);
}, ERROR_STRATEGIES.MODAL);
} else {
this.get("user").rollbackAttributes();
Expand Down
Loading

0 comments on commit 55509e9

Please sign in to comment.