Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/revert-34044-em/icons-alt-text' …
Browse files Browse the repository at this point in the history
…into autostaging
  • Loading branch information
nospame committed Feb 26, 2024
2 parents ce94768 + 4fbd98b commit f6b57ab
Show file tree
Hide file tree
Showing 20 changed files with 85 additions and 340 deletions.
12 changes: 1 addition & 11 deletions corehq/apps/app_manager/app_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def _create_module_details_app_strings(module, langs):
clean_trans(column.header, langs)
)

if column.format in ('enum', 'conditional-enum', 'enum-image', 'clickable-icon'):
if column.format in ('enum', 'enum-image', 'conditional-enum', 'clickable-icon'):
for item in column.enum:
yield (
id_strings.detail_column_enum_variable(
Expand All @@ -166,16 +166,6 @@ def _create_module_details_app_strings(module, langs):
),
clean_trans(item.value, langs)
)
if module.get_app().supports_alt_text and column.format in ('enum-image', 'clickable-icon'):
yield (
id_strings.detail_column_alt_text_variable(
module,
detail_type,
column,
item.key_as_variable,
),
clean_trans(item.alt_text, langs)
)
elif column.format == "graph":
for index, item in enumerate(column.graph_configuration.annotations):
yield (
Expand Down
26 changes: 0 additions & 26 deletions corehq/apps/app_manager/detail_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,6 @@ def sort_xpath_function(self):
def action(self):
return None

@property
def alt_text(self):
return None

@property
def fields(self):
print_id = None
Expand All @@ -305,7 +301,6 @@ def fields(self):
sort_node=self.sort_node,
print_id=print_id,
endpoint_action=self.action,
alt_text=self.alt_text,
)
elif self.sort_xpath_function and self.detail.display == 'short':
yield sx.Field(
Expand Down Expand Up @@ -480,27 +475,6 @@ def action(self):
if self.column.endpoint_action_id and self.app.supports_detail_field_action:
return sx.EndpointAction(endpoint_id=self.column.endpoint_action_id, background="true")

def _make_alt_text(self, type):
return sx.XPathEnum.build(
enum=self.column.enum,
format=self.column.format,
type=type,
template=self._xpath_template(type),
get_template_context=self._xpath_template_context(type),
get_value=lambda key: self.id_strings.detail_column_alt_text_variable(self.module, self.detail_type,
self.column, key))

@property
def alt_text_xpath(self):
return self._make_alt_text('display')

@property
def alt_text(self):
if self.app.supports_alt_text:
return sx.AltText(
text=sx.Text(xpath=self.alt_text_xpath)
)

def _xpath_template(self, type):
return "if({key_as_condition}, {key_as_var_name}"

Expand Down
9 changes: 0 additions & 9 deletions corehq/apps/app_manager/feature_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,3 @@ def supports_grouped_case_search_properties(self):
return (
self._require_minimum_version('2.54')
)

@property
def supports_alt_text(self):
"""
Alt text for case list icons and clickable icons
"""
return (
self._require_minimum_version('2.54')
)
13 changes: 0 additions & 13 deletions corehq/apps/app_manager/id_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,6 @@ def detail_column_enum_variable(module, detail_type, column, key_as_var):
)


@pattern('m%d.%s.%s_%s_%s.alt_text.%s')
def detail_column_alt_text_variable(module, detail_type, column, key_as_var):
field = _clean_field_for_mobile(column.field)
return "m{module.id}.{detail_type}.{d.model}_{field}_{d_id}.alt_text.{key_as_var}".format(
module=module,
detail_type=detail_type,
d=column,
field=field,
d_id=column.id + 1,
key_as_var=key_as_var,
)


@pattern('m%d.%s.%s_%s_%s.graph.key.%s')
def graph_configuration(module, detail_type, column, key):
field = _clean_field_for_mobile(column.field)
Expand Down
1 change: 0 additions & 1 deletion corehq/apps/app_manager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,6 @@ class MappingItem(DocumentSchema):
key = StringProperty()
# lang => localized string
value = DictProperty()
alt_text = LabelProperty()

@property
def treat_as_expression(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ hqDefine('app_manager/js/app_manager_media', function () {
return self.savedPath();
});

self.altText = ko.observable(o.ref.alt_text);

self.multimediaObject = ko.computed(function () {
return self.objectMap()[self.currentPath()];
});
Expand Down Expand Up @@ -154,12 +152,12 @@ hqDefine('app_manager/js/app_manager_media', function () {
var MenuMediaReference = function (ref) {
'use strict';
var self = {};

self.path = ref.path || '';
self.iconType = ref.icon_class || '';
self.mediaType = ref.media_class || '';
self.module = ref.module;
self.form = ref.form;
self.altText = ref.alt_text || '';

return self;
};
Expand Down
7 changes: 1 addition & 6 deletions corehq/apps/app_manager/suite_xml/xml_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,10 +717,6 @@ class Template(AbstractTemplate):
ROOT_NAME = 'template'


class AltText(AbstractTemplate):
ROOT_NAME = 'alt_text'


class GraphTemplate(Template):
# TODO: Is there a way to specify a default/static value for form?
form = StringField('@form', choices=['graph'])
Expand Down Expand Up @@ -853,7 +849,7 @@ class EndpointAction(XmlObject):

class Field(OrderedXmlObject):
ROOT_NAME = 'field'
ORDER = ('style', 'header', 'template', 'endpoint_action', 'sort_node', 'alt_text')
ORDER = ('style', 'header', 'template', 'endpoint_action', 'sort_node')

sort = StringField('@sort')
print_id = StringField('@print-id')
Expand All @@ -863,7 +859,6 @@ class Field(OrderedXmlObject):
sort_node = NodeField('sort', Sort)
background = NodeField('background/text', Text)
endpoint_action = NodeField('endpoint_action', EndpointAction)
alt_text = NodeField('alt_text', AltText)


class Lookup(OrderedXmlObject):
Expand Down
37 changes: 0 additions & 37 deletions corehq/apps/app_manager/tests/test_app_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
CaseSearchAgainLabel,
CaseSearchLabel,
CaseSearchProperty,
MappingItem,
)
from corehq.apps.app_manager.tests.app_factory import AppFactory
from corehq.apps.app_manager.tests.util import SuiteMixin
Expand Down Expand Up @@ -306,39 +305,3 @@ def test_select_text_app_strings(self):

es_app_strings = self._generate_app_strings(app, 'fra', build_profile_id='fra')
self.assertEqual(es_app_strings['m0_select_text'], 'Continuer avec le cas')

def test_alt_text_app_strings(self):
factory = AppFactory(build_version='2.54.0')
factory.app.langs = ['en', 'fra']
factory.app.build_profiles = OrderedDict({
'en': BuildProfile(langs=['en'], name='en-profile'),
'fra': BuildProfile(langs=['fra'], name='fra-profile'),
})
module, form = factory.new_basic_module('my_module', 'cases')

short_column = module.case_details.short.get_column(0)
short_column.format = 'clickable-icon'
short_column.model = 'case'
short_column.field = 'is_favorite'
short_column.enum = [
MappingItem(
key='true',
value={
'en': 'jr://image_is_favorite.png',
'fra': 'jr://image_is_favorite.png',
},
alt_text={
'en': 'filled yellow star',
'fra': 'étoile jaune remplie',
}
),
]

app = Application.wrap(factory.app.to_json())

en_app_strings = self._generate_app_strings(app, 'default', build_profile_id='en')
self.assertEqual(en_app_strings['m0.case_short.case_is_favorite_1.alt_text.ktrue'], 'filled yellow star')

fra_app_strings = self._generate_app_strings(app, 'fra', build_profile_id='fra')
self.assertEqual(fra_app_strings['m0.case_short.case_is_favorite_1.alt_text.ktrue'],
'étoile jaune remplie')
50 changes: 0 additions & 50 deletions corehq/apps/app_manager/tests/test_suite_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,56 +245,6 @@ def test_case_detail_icon_mapping(self, *args):
'jr://icons/10-year-old.png'
)

def test_case_detail_alt_text_mapping(self, *args):
factory = AppFactory(domain='domain', name='Case list field actions', build_version='2.54.0')
m0, f0 = factory.new_basic_module("module1", "case")
factory.form_requires_case(f0)

f1 = factory.new_form(m0)
factory.form_requires_case(f1)

m0.case_details.short.columns = [
DetailColumn(
header={'en': 'Starred'},
model='case',
field='starred',
format='enum-image',
enum=[
MappingItem(key='1', value={'en': 'jr://icons/star-gold.png'}, alt_text={'en': 'gold star'}),
MappingItem(key='0', value={'en': 'jr://icons/star-grey.png'}, alt_text={'en': 'grey star'}),
],
),
]

key1 = '1'
key2 = '0'

alt_text_spec = """
<partial>
<alt_text>
<text>
<xpath function="if(starred = '{key1}', $k{key1}, if(starred = '{key2}', $k{key2}, ''))">
<variable name="k{key1}">
<locale id="m0.case_short.case_starred_1.alt_text.k{key1}"/>
</variable>
<variable name="k{key2}">
<locale id="m0.case_short.case_starred_1.alt_text.k{key2}"/>
</variable>
</xpath>
</text>
</alt_text>
</partial>
""".format( # noqa: #501
key1=key1,
key2=key2
)
# check correct suite is generated
self.assertXmlPartialEqual(
alt_text_spec,
factory.app.create_suite(),
'./detail[@id="m0_case_short"]/field[1]/alt_text'
)

def test_case_detail_address_popup(self, *args):
app = Application.new_app('domain', 'Untitled Application')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,13 @@ hqDefine("cloudcare/js/formplayer/menus/controller", function () {
var headers = detailObject.get('headers');
var details = detailObject.get('details');
var styles = detailObject.get('styles');
var altText = detailObject.get('altText');
var detailModel = [];
// we need to map the details and headers JSON to a list for a Backbone Collection
for (i = 0; i < headers.length; i++) {
var obj = {};
obj.data = details[i];
obj.header = headers[i];
obj.style = styles[i];
obj.altText = altText[i];
obj.id = i;
if (obj.style.displayFormat === constants.FORMAT_MARKDOWN) {
obj.html = markdown.render(details[i]);
Expand All @@ -300,7 +298,7 @@ hqDefine("cloudcare/js/formplayer/menus/controller", function () {

return {
styles: _.map(indices, index => detailObject.styles[index]),
altText: _.map(indices, index => detailObject.altText[index]),
headers: _.map(indices, index => detailObject.headers[index]),
tiles: _.map(indices, index => detailObject.tiles[index]),
details: _.map(indices, index => detailObject.details[index]),
};
Expand All @@ -310,13 +308,12 @@ hqDefine("cloudcare/js/formplayer/menus/controller", function () {
var getCaseTile = function (detailObject) {
var {
styles,
altText,
headers,
tiles,
details,
} = onlyVisibleColumns(detailObject);
var detailModel = new Backbone.Model({
data: details,
altText,
id: 0,
});
var numEntitiesPerRow = detailObject.numEntitiesPerRow || 1;
Expand All @@ -332,6 +329,7 @@ hqDefine("cloudcare/js/formplayer/menus/controller", function () {
$("#persistent-cell-grid-style").html(caseTileStyles.cellGridStyle).data("css-polyfilled", false);
return views.PersistentCaseTileView({
model: detailModel,
headers: headers,
styles: styles,
tiles: tiles,
maxWidth: detailObject.maxWidth,
Expand Down
Loading

0 comments on commit f6b57ab

Please sign in to comment.